HTML & CSS Wiki
Advertisement


The <script></script> element links to or encloses source code of a given type such as "text/javascript" (JavaScript, the default but included for compatibility with older browsers), which operates on the containing HTML document. Other languages such as VBScript, which is only compatible with Internet Explorer, may be used by specifying the appropriate MIME type in the type attribute. But no practical purpose currently exists to do this, as JavaScript works in all the same browsers and more.

Attributes[]

Optional attributes[]

Values listed in ( ) (parentheses or round brackets), separated by | (pipes or vertical bars), are for enumerated attributes; the bold value is the default.

Attribute Value Description
src URL The location of a script file.
async async If present, the script will be loaded immediately but will not block loading of other page elements. Must not be used with defer. If neither async nor defer is specified, the script will load immediately and block the rest of the page.
defer defer If present, loading of the script will be blocked by all other page elements. Must not be used with async. If neither async nor defer is specified, the script will load immediately and block the rest of the page.
type ( text/javascript
| any other MIME type corresponding to a scripting language )
Determines the scripting language used for parsing the element's contents, if it is supported by the browser. Unsupported scripts are ignored.
charset a character encoding MIME type If src is also specified, the character encoding to use for reading it; otherwise, this attribute is invalid. If given, must match the value provided in the server's HTTP Content-Type response header.

Global attributes[]

See Global HTML Attributes.

See also[]

External links[]

Advertisement