HTML <script> Tag
Description
The <script> tag in HTML is used to embed or reference executable code within a web page. It is primarily associated with JavaScript, allowing developers to add dynamic behavior, manipulate the Document Object Model (DOM), handle events, perform calculations, and interact with external data sources. Scripts can be placed either in the <head> or <body> sections of a document, depending on when the code should be executed relative to the page’s content.
When a script is embedded directly inside the <script> tag, the code is written inline, allowing immediate execution by the browser. Alternatively, the <script> tag can reference an external file containing the script, enabling code reuse across multiple pages and improved maintainability. Scripts can be synchronous, blocking the page rendering until execution completes, or asynchronous, allowing the page to continue loading while the script runs.
The <script> tag is essential for modern web development, supporting interactive features such as form validation, dynamic content updates, animations, API requests, and rich user interfaces. It serves as the bridge between static HTML content and the interactive, programmatically controlled behavior that users experience on dynamic websites.
Properties
- Permitted Parents
- Any element that accepts metadata content, or any element that accepts phrasing content
- Content
- Text
- Start/End Tags
- Start tag: required, End tag: required
Example
Attributes
- 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 information will show you the current browser support for the HTML <script> tag. Hover over a browser icon to see the version that first introduced support for this HTML tag.
This tag is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 26th December 2025
