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

html
Try it Yourself
Live 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
AttributeValuesDefaultDescription
asyncasyncnoneSpecifies 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)
crossoriginanonymoususe-credentialsnoneSets the mode of the request to an HTTP CORS Request
deferdefernoneSpecifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing (only for external scripts)
integrityfilehashnoneAllows a browser to check the fetched script to ensure that the code is never loaded if the source has been manipulated
nomoduleTrueFalsenoneSpecifies that the script should not be executed in browsers supporting ES2015 modules
referrerpolicyno-referrerno-referrer-when-downgradeorigin origin-when-cross-originsame-originstrict-origin strict-origin-when-cross-originunsafe-urlnoneSpecifies which referrer information to send when fetching a script
srcURLnoneSpecifies the URL of an external script file
typescripttypenoneSpecifies 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-*.

HTML Global Attributes Reference →
Event Attributes

The <script> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.

HTML Event Attributes Reference →

Browser Compatibility

ChromeEdgeFirefoxSafariOpera

More Tags in Scripting & Styles

View All 123Tags →