HTML <script> Tag


The <script> HTML element is intended to describe scripts; it may contain a link to the program or its text in a certain language. Scripts can be located in an external file and link to any HTML document. This approach allows you to use the same common functions on many web pages and speeds up their loading, because the external file is cached on first load, and the script is called faster on subsequent calls.
<script> can be located in the header or body of an HTML document in unlimited quantities. In most cases, the location of the script does not affect the operation of the program. However, scripts that must be executed first are usually placed in the title of the document.


Permitted Parents
Any element that accepts metadata content, or any element that accepts phrasing content
Start/End Tags
Start tag: required, End tag: required


<script type="text/javascript">
document.write("Hello World!")


Attribute Definition
async Specifies that the script is executed asynchronously (only for external scripts)
charset Defines the character encoding that the script uses.
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 Specifies a URI/URL of an external script.
type Specifies the scripting language as a content-type (MIME type).

Global Attributes

The <script> tag also supports the Global Attributes in HTML5

Event Attributes

The <script> tag also supports the Event Attributes in HTML5

Browser Support

The following table will show you the current browser support for the HTML <script> tag.

Edge Chrome Firefox Opera Safari
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview

Last updated by CSSPortal on: 30th March 2024