This <script> element contains the scripts that will be executed in the page, and it can occur in either the <head> or the <body> section of the page.
<script> |
Yes | Yes | Yes | Yes | Yes |
The "type" attribute is required in HTML 4, but optional in HTML5.
The "async" attribute is new in HTML5.
Attribute | Value | Description |
---|---|---|
async | async | Set that the script is executed asynchronously (only valid for external scripts) |
charset | charset | Set the character encoding used in an external script file |
defer | defer | Set that the script is executed when the page has finished parsing (only valid for external scripts) |
src | URL | Set the URL of an external script file |
type | media_type | Set the media type of the script |
xml:space | preserve | Not supported in HTML5. Set whether whitespace in code should be preserved |
The <script> tag supports the Global Attributes in HTML.
The <script> tag supports the Event Attributes in HTML.
script { display: none; }
A demo showing how to use <script> tag.
<html> <head> <script language="javascript" src="yourlinkedjavascriptfile.js"></script> <script id="script1" language="javascript"> //scriptcode declarations </script> </head> <body> <script id="script2" language="javascript"> //script code declarations </script> </body> </html>