The script tag is used to embed a client-side script like JavaScript.
The <script> tag can either wrap around scripting elements or it can link to an external script using the src attribute.
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
<script src="external-script.js" type="text/javascript"></script>async
Used for external scripts, this attribute designates that the script is downloaded in parallel with the page and executed immediately upon availability.
crossorigin
Sets the request mode to an HTTP CORS request. Possible values: anonymous and user-credentials.
defer
Used for external scripts, this attribute designates that the script is downloaded in parallel with the page and executed after the rest of the page is loaded.
integrity
Checks the external script to make sure the code is not loaded if the source has been manipulated.
nomodule
Designates that the script will not be executed when the browser supports ES2015 modules.
referrerpolicy
Determines which referrer information is sent when fetching the script. Possible values: no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, and unsafe-url.
src
Sets the URL address of the external script file.
type
Designates the script’s media type.
Have a code example of <script>? Submit a codepen.io demo and we'll showcase it here ↴