HTML <script> Tag


Advertisements


Description

The HTML <script> tag is used for declaring a script (such as JavaScript) within your HTML document.

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML script Tag</title>
</head>
<body>
<script type="text/javascript">

      document.write("You're visiting tutorialspoint!")

</script>

</body>
</html>

This will produce following result:

For more detail on <script> tag please check HTML Scripts chapter.

Global Attributes

This tag supports all the global attributes described in - HTML Attribute Reference

Specific Attributes

The HTML <script> tag also supports following additional attributes:

AttributeValueDescription
async html-5syncSpecifies that the script is executed asynchronously.
charset charsetDefines the character encoding that the script uses.
defer deferDeclares that the script will not generate any content. Therefore, the browser/user agent can continue parsing and rendering the rest of the page.
src URLSpecifies a URI/URL of an external script.
type text/javascript
application/ecmascript
application/javascript
text/vbscript
Specifies the scripting language as a content-type (MIME type).
xml:space preserveDeprecated- Whether the whitespace in code should be preserved

Event Attributes

This tag supports all the event attributes described in - HTML Events Reference

Browser Support

ChromeFirefoxIEOperaSafariAndroid
YesYesYesYesYesYes

html_tag_reference.htm