HTML - <script> Tag



The HTML <script> tag is used for declaring a script (such as JavaScript) within your HTML document.


<!DOCTYPE html>

      <title>HTML script Tag</title>

      <script type = "text/JavaScript">
         document.write("You're visiting tutorialspoint!")

This will produce the following result −

For more detail on <script> tag please check HTML Scripts chapter.

Global Attributes

This tag supports all the global attributes described in − HTML Attribute Reference

Specific Attributes

The HTML <script> tag also supports the following additional attributes −

Attribute Value Description
async html-5 sync Specifies that the script is executed asynchronously.
charset charset Defines the character encoding that the script uses.
defer defer Declares that the script will not generate any content. Therefore, the browser/user agent can continue parsing and rendering the rest of the page.
src URL Specifies a URI/URL of an external script.
type text/JavaScript
Specifies the scripting language as a content-type (MIME type).
xml:space preserve Deprecated − Whether the whitespace in code should be preserved

Event Attributes

This tag supports all the event attributes described in − HTML Events Reference

Browser Support

Chrome Firefox IE Opera Safari Android
Yes Yes Yes Yes Yes Yes