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


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



  • HTML 4.01
  • HTML5


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


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


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.


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


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.


Values: URL
Provides the location of an external script.


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.


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 ...
// ]]>
// <![CDATA[
... JavaScript code goes here ...
// ]]>

Rendered Example

script is a non-rendering element.