HTML script Tag

HTML <script>Tag: The HTML<script> tag specifies client-side script.  The <script> element either contains scripting statements, or it points to an external script file through the src attribute. While the JavaScript is mainly used in form validation, dynamic changes of content, image manipulation etc.

HTML<script>Tag

This HTML script tag supports both the global and the event attributes.

Syntax: <script> Text </script>

Attributes

Many attributes associated with the script tag.

  • async: It is used to specify the script is executed asynchronously.
  • charset: It is used to specify the character encoding used in an external script file.
  • defer: It is used to specify that the script is executed when the page has finished parsing.
  • src: It is used to specify the URL of an external script file.
  • type: It is used to specify the media type of the script.

Browser compatibility

The HTML<script> tag is supported by different types of browsers.

  • Chrome
  • Firefox
  • Opera
  • Safari
  • Internet Explorer

Example:

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Visit https://www.freshersnow.com/!";
</script> 
</body>
</html>

Output:

Visit https://www.freshersnow.com!

Attributes that are supported by the <script> tag

Attribute Value Description
charset charset Specifies the character encoding used in an external script file
defer defer Specifies that the script is executed when the page has finished parsing
src URL Specifies the URL of an external script file
type media_type Specifies the media type of the script
xml:space preserve Specifies whether whitespace in the code should be preserved