Name

script — HTML 4.01 | HTML5

Synopsis

<script> . . . </script>

Places a script in the document (usually JavaScript for web documents). It may appear any number of times in the head or body of the document. The script may be provided in the script element or in an external file (by providing the src attribute).

Notes

In XHTML, when the script is provided as the content of the script element (i.e., not as an external file), the script should be contained in a CDATA section as shown in the example below.

Start/End Tags

Required/Required

Attributes

HTML5 Global Attributes

async (async="async" in XHTML5)

HTML5 only. Indicates the script should be executed asynchronously, as soon as it is available.

charset="character set"

Indicates the character encoding of an external script document (it is not relevant to the content of the script element).

defer (defer="defer" in XHTML)

Indicates to the user agent that the script should be executed when the page is finished parsing.

id="text"

XHTML and HTML5. Assigns a unique identifying name to the element.

language="text"

Deprecated. Provides the name of the scripting language, but since it is not standardized, it has been deprecated in favor of the type attribute.

src="URL"

Provides the location of an external script.

type="content-type"

Required in HTML 4.01. Optional in HTML5 if using JavaScript. Specifies the scripting language used for the current script. This setting overrides any default script setting for the document. The value is a content type, most often ...

Get HTML & XHTML Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.