HTML Tags: Scripting

These are the HTML tags you use to embed scripts.

TagTypeDescription
<script>OtherEmbeds JavaScript to page
<noscript>InlineContains HTML to display if scripting is disabled

<script>

Embeds JavaScript to page.

You can put the script inline between <script>...</script>, or import it from an external source using <script src="...">.

You can put <script> inside <head>, but if you load an external script this way, the browser will wait until the script is loaded and executed before continuing to parse the rest of the HTML (see Render-Blocking JavaScript).

Common attributes
  • src=[...] — URL to the external script
  • type=[...] — type of the script represented. Can be:
    • text/javascript, or its equivalents, or omitted entirely (doesn't do anything as it's inferred by default; HTML5 specification urges you to not write it.)
    • module (causes the code to be treated as JavaScript module; allows you to use the import and export syntax.)
    • other values (the <script> content will be treated as a data block, which will not be processed by the browser.)
  • nomodule — indicates that the script should not be executed in browsers that support JavaScript module (can be used to serve fallback scripts in older browsers).
Attributes related to loading
  • async=[...] — fetch the script in parallel to parsing (asynchronously), and execute it as soon as it is available.
  • defer=[...] — fetch the script in parallel to parsing (asynchronously), and execute it in order of appearance when the document has finished parsing (this will block DOMContentLoaded event until the deferred script has finished executing)
Attributes related to security
  • integrity=[...] — hash of resource to make sure it hasn't been tampered
  • nonce=[...] — Nonce for script-src CSP
  • crossorigin=[...] read here
  • referrerpolicy=[...] read here
| LIVE PREVIEW

<noscript>

HTML to display if scripting is disabled.

| LIVE PREVIEW
Try disabling JavaScript on your browser:

References