Name

script — <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).

Attributes

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"

Indicates to the user agent that the script will not generate document content, so the user agent may continue rendering.

id="text"

XHTML only. 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 . 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 text/javascript.

xml:space="preserve"

XHTML only. Instructs XML processors to preserve the whitespace in the element.

Example

<script type="text/javascript">
  // <![CDATA[
  . . .  JavaScript code goes here . . .
  // ]]>
</script>

Get HTML and XHTML Pocket Reference, 3rd 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.