Loading...
HTML <script> Tag

HTML <script> Tag

In this tutorial, we will learn about script tag in HTML with the help of examples.


<script> Tag

Script tag <script> is used to declare or point to an external script file through the src attribute within your HTML file (such as Javascript).

Note : We can also use <script> tag inside the <head> tag.

Syntax

<script>.........</script>

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Script Tag</title>
    <script>
       document.getElementById("demo").innerHTML = "Hello Javascript!";
    </script>
  </head>
  <body>
    <p>In this HTML document we have use script tag.</p>
  </body>
</html>

Output

In this HTML document we have use script tag.


Specific Attribute

Attribute Value Description
async sync It specifies that the script is executed asynchronously
charset charset It defines the character encoding that the script uses
defer defer It is used to declare 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 It specifies a URI/URL of an external script
type text/Javascript application/Javascript text/vbscript It specifies the scripting language as a content-type (MIME type)
xml:space preserve It specifies whether the whitespace in code should be preserved

Global Attribute

Script Tag support all the global attributes of HTML.


Event Attribute

Script Tag support all the event attributes of HTML.


Next Tutorial

We hope that this tutorial helped you develop better understanding of the concept of <script> tag in HTML.

Keep Learning : )

In the next tutorial, you'll learn about HTML <section> Tag.

- Related Topics