HTML - <script> Tag


Advertisements


Description

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

Example

Live Demo
<!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 the 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 the following additional attributes −

Attribute Value Description
async html-5 sync Specifies that the script is executed asynchronously.
charset charset Defines the character encoding that the script uses.
defer defer Declares that the script will not generate any content. Therefore, the browser/user agent can continue parsing and rendering the rest of the page.
src URL Specifies 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 preserve Deprecated − Whether the whitespace in code should be preserved

Event Attributes

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

Browser Support

Chrome Firefox IE Opera Safari Android
Yes Yes Yes Yes Yes Yes

html_tags_reference.htm

Advertisements