
- HTML - Home
- HTML - Roadmap
- HTML - Introduction
- HTML - History & Evolution
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <script> Tag
The HTML <script> tag is used to declare Client-side script (JavaScript). The tag may either contain a link to an external file with scripts or the script itself.
The <script> tag is used to define client-side script for image manipulation, form validation, and dynamic content updates. The src attribute specifies the location of an external file.
The HTML <script> tag can be placed in both <head> and <body> elements. Although the script's location within an HTML document does not affect its execution, scripts that must run first should be placed in the document's heading. An HTML document can contain multiple instances of the <script>.
Syntax
Following is the syntax of <script> tag −
<script> .... </script>
Attributes
The HTML <script> tag supports Global and accepts specific attributes, which is are listed below.
Attribute | Value | Description |
---|---|---|
async | async | Specifies that the script executes asynchronously. |
crossorigin | anonymous use-credentials |
Specifies the mode of the request for an HTTP CORS request. |
defer | Specifies that the script will not generate any content, allowing the browser or user agent to continue parsing and rendering the rest of the page. | |
nomodule | true false |
Specifies that the script should not be executed in browsers supporting ES6 modules |
integrity | filehash | Allows the browser to check the fetched script to ensure the code is never loaded if the source has been manipulated. |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin same-origin strict-origin strict-origin-when-cross-origin unsafe-url |
Specifies which referrer information to send when fetching a script |
src | Specifies the URI/URL path of an external script. | |
type | Specifies the scripting language as a content-type (MIME type). |
Example: Internal JavaScript Using <script> Tag
Lets look at a basic example of using the <script> tag. In this example, we use internal JavaScript code within the <script> tag. This HTML code displays the message.
<!DOCTYPE html> <html> <head> <title>HTML script Tag</title> </head> <body style="background-color:#EAFAF1 "> <script type = "text/JavaScript"> document.write("You're visiting tutorialspoint!") </script> </body> </html>
Example: External JavaScript Using <script> Tag
Consider another scenario where we place the <script> tag outside the <body> tag. This HTML code links to an external JavaScript file, "index.js", and displays the heading "TutorialsPoint" on the webpage.
<!DOCTYPE html> <html> <head> <script src="index.js" type="text/script"></script> </head> <body> <h1>TutorialsPoint</h1> </body> </html>
Example: Multiple <script> Tags
In the following example, where we are going to use multiple <script> tag for each JavaScript code. This code will generate an output, triggering the script tag to display two alerts and text on the webpage. This HTML code displays two alert messages.
<!DOCTYPE html> <html> <head> <script> alert('WELCOME TO') </script> </head> <body> <h2>The Best E-Way Learning.!</h2> <script> alert('TUTORIALSPOINT') </script> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
script | Yes | Yes | Yes | Yes | Yes |