Scripting & Styles
HTML <script> Tag
The <script> tag is used to embed a client-side script (JavaScript).
Definition and Usage
The <script> tag is used to embed a client-side script (JavaScript).
Standard Syntax:
<script>...</script>Interactive ExampleRunnable
HTML <script> Example
htmlLive code demonstration for the <script> tag. Click "Try it Yourself" to edit and experiment in real time.
<div style="font-family: system-ui, sans-serif; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; color: #0f172a;">
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</div>Attributes for <script>
8 Supported Attributes| Attribute | Values | Default | Description |
|---|---|---|---|
| async | async | none | Specifies that the script is downloaded in parallel to parsing the page, and executed as soon as it is available (before parsing completes) (only for external scripts) |
| crossorigin | anonymoususe-credentials | none | Sets the mode of the request to an HTTP CORS Request |
| defer | defer | none | Specifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing (only for external scripts) |
| integrity | filehash | none | Allows a browser to check the fetched script to ensure that the code is never loaded if the source has been manipulated |
| nomodule | TrueFalse | none | Specifies that the script should not be executed in browsers supporting ES2015 modules |
| referrerpolicy | no-referrerno-referrer-when-downgradeorigin origin-when-cross-originsame-originstrict-origin strict-origin-when-cross-originunsafe-url | none | Specifies which referrer information to send when fetching a script |
| src | URL | none | Specifies the URL of an external script file |
| type | scripttype | none | Specifies the media type of the script |
Global Attributes
The <script> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.
Event Attributes
The <script> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.
Browser Compatibility
ChromeEdgeFirefoxSafariOpera
More Tags in Scripting & Styles
View All 123Tags →<details>The <details> tag specifies additional details that the user can open and close on demand.<dialog>The <dialog> tag defines a dialog box or subwindow.<noscript>The <noscript> tag defines an alternate content to be displayed to users that have disabled scripts in their browser or have a browser that doesn't support script.<search>The <search> tag is used to specify that here comes a set of elements that is related to search.<style>The <style> tag is used to define style information (CSS) for a document.<summary>The <summary> tag defines a visible heading for the <details> element. The heading can be clicked to view/hide the details.