HTML <script> tag

Updated: 11/13/2018 by Computer Hope
HTML script tag

When writing in HTML, the <script> tag is an inline element used to designate a client-side script on a web page. The <script> tag either points to an external script file or contains scripting statements. It is useful for adding things like dynamic content or form validation. The following sections contain information about this tag, including an example of it in use, as well as related attributes and browser compatibility.

Example of <script> code

<script>document.write("Your browser supports JavaScript!")</script>
<noscript>Sorry, your browser does not support JavaScript.</noscript>

Example result

Example explanation

If you browser supports JavaScript, you should see the message "Your browser supports JavaScript!" If not, you should see the message "Sorry, your browser does not support JavaScript."


Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The following table shows all of the current unique HTML attributes for the <script> tag, as well as a description of each.


The type attribute is optional in HTML5, but still required in HTML 4.

Attribute Description
async Designates that the script should be executed asynchronously (external scripts only).
charset Designates the character encoding used with an external script file.
defer Designates that the script is executed once the page has finished parsing (external scripts only).
src Designates the URL of an external script file.
type Designates the script's media type.

Deprecated attributes

A deprecated attribute is one that may function currently but is not supported in going forward. While the attribute may work with the current version of HTML, it will eventually be phased out. It is better to avoid using these attributes to help future-proof your website.

Attribute Description
xml:space Designates whether or not whitespace in code should be preserved.


Edge Internet Explorer Firefox Safari Opera Chrome
All versions All versions All versions All version All versions All versions

Author, Browser, Client-side, Compatibility, CSS, HTML noscript tag, Parse, Web design terms, Whitespace