script

FilterElements

<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 section.

Start/End Tags

Required/Required

Specifications

  • HTML 4.01
  • HTML5

async

Values: None in HTML. (async="async" in XHTML5)
HTML5 only. Indicates the script should be executed asynchronously, as soon as it is available.

charset=

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

defer

Values: None in HTML. (defer="defer" in XHTML)
Indicates to the user agent that the script should be executed when the page is finished parsing.

id=

Values: text
XHTML and HTML5 only. Assigns a unique identifying name to the element.

language=

Values: 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=

Values: URL
Provides the location of an external script.

type=

Values: 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 text/javascript.

xml:space=

Values: preserve
XHTML only. Instructs XML processors to preserve the whitespace in the element.
HTML 4.01 and XHTML 1.0
<script type="text/javascript">
// <![CDATA[
... JavaScript code goes here ...
// ]]>
</script>
HTML5
<script>
// <![CDATA[
... JavaScript code goes here ...
// ]]>
</script>

Rendered Example

script is a non-rendering element.