CSS Portal

HTML <script> Tag

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
<script>
HTML TagThis tag is supported by all modern browsers.
Updated 26th December 2025

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

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

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

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee