Signup/Sign In
PUBLISHED ON: FEBRUARY 22, 2021

HTML Script Tag

In HTML, the <script> tag is used to embed some executable code.

  • The <script> tag is mainly used to refer to javascript (client-side script) code in an HTML document. It can also be used with some other languages Like GLSL shader programming Language

  • The <script> tag must be empty if the src attribute is present.

  • Also, this is a Block-Level Element.

HTML <script> Tag Syntax and Usage

Given below is the basic syntax of <script> tag:

<script>
.....content here
</script>

HTML <script> Tag Attributes

HTML <script> tag supports both global and event attributes and some of the common attributes are given below:

1. Type

This attribute is used to define the type of script in the document.

2. Text

This attribute is used to sets the text content for the element.

3. Async

This is a Boolean attribute indicating that the browser should if it is possible; load the script asynchronously.

4. Src

This attribute is used to specify the URL for external CSS Files.

5. Defer

It is a boolean attribute and it is set to indicate a browser that the script is meant to be executed after the document has been parsed.

HTML <script> Tag Basic Example

Below we have a basic example of <script> tag:

Default CSS Settings for HTML <script> Tag

Given below are the default CSS settings used by most of the browsers:-

script {
  display: none;
}

Browser Support for HTML <script> Tag

Following browsers support this attribute:

  • Google Chrome 6.0+

  • Internet Explorer 9.0+

  • Firefox 4+

  • Opera 11.1+

  • Safari 5.0+



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.