The script element either contains scripting statements or it points to an external script file through the src attribute.
The required type attribute specifies the MIME type of the script.
Browser SupportThe <script> tag is supported in all major browsers.
Differences Between HTML and XHTMLHTML 4 and XHTML deal different with the content inside scripts:
- In HTML 4, the content type is declared as CDATA, which means that entities will not be parsed.
- In XHTML, the content type is declared as (#PCDATA), which means that entities will be parsed.
To ensure that a script parses correctly in an XHTML document, use the following syntax:
Tips and NotesTip: Also look at the noscript element for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.
Required AttributesDTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
|type||MIME-type||Specifies the MIME type of a script||STF|
|charset||charset||Specifies the character encoding used in an external script file||STF|
|defer||defer||Specifies that the execution of a script should be deferred (delayed) until after the page has been loaded||STF|
|src||URL||Specifies the URL of an external script file||STF|
|xml:space||preserve||Specifies whether whitespace in code should be preserved|