HTML Tags: Scripting
These are the HTML tags you use to embed scripts.
Tag | Type | Description |
---|---|---|
<script> | Other | Embeds JavaScript to page |
<noscript> | Inline | Contains 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).
src=[...]
— URL to the external scripttype=[...]
— 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 theimport
andexport
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).
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 blockDOMContentLoaded
event until the deferred script has finished executing)
integrity=[...]
— hash of resource to make sure it hasn't been tamperednonce=[...]
— Nonce forscript-src
CSPcrossorigin=[...]
— read herereferrerpolicy=[...]
— read here
| LIVE PREVIEW
<noscript>
HTML to display if scripting is disabled.
| LIVE PREVIEW
Try disabling JavaScript on your browser:
References
- HTML elements reference (MDN) — https://developer.mozilla.org/en-US/docs/Web/HTML/Element
- Eliminate Render-Blocking JavaScript with Async and Defer: Async vs Defer — https://www.digitalocean.com/community/tutorials/html-defer-async