HTML5 <script> Tag – Usage, Attributes and Examples
<script> tag is used to embed or reference an executable script.
The only content permitted inside this element is dynamic script such as
<script> tag can be any element that accepts metadata content, or any element that accepts phrasing content.
Scripts without async or defer attributes, as well as inline scripts, are fetched and executed immediately, before the browser continues to parse the page. The script should be served with the
image/*), a video type (
video/*), an audio (
audio/*) type, or
text/csv. If the script is blocked, an error is sent to the element, if not a success event is sent.
Here is an example of using this tag:
Set this Boolean attribute to indicate that the browser should, if possible, execute the script asynchronously. It has no effect on inline scripts (i.e., scripts that don’t have the src attribute).
Contains inline metadata that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation.
This attribute specifies the URI of an external script. This can be used as an alternative to embedding a script directly within a document. If a script element has a
src attribute specified, it should not have a script embedded inside its tags.
This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s
src attribute. This is specified as a MIME type; examples of supported MIME types include
textContent attribute, this attribute sets the text content of the element. Unlike the
textContent attribute, however, this attribute is evaluated as executable code after the node is inserted into the DOM.
This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing
DOMContentLoaded. The defer attribute should only be used on external scripts.
Normal script elements pass minimal information to the
window.onerror for scripts which do not pass the standard CORS checks. To allow error logging for sites which use a separate domain for static media, use this attribute.
- Read more about the HTML
<script>element on MDN.
- You can also read the HTML
<script>tag reference on W3C.
Rate this post —