Open In App
Related Articles

HTML script Tag

Improve Article
Improve
Save Article
Save
Like Article
Like

The <script> tag is used to define the client-side script. This tag contains the scripting statements, or it points to an external script file. JavaScript is mainly used in HTML to change the content, images, form validation, and stylings of the page dynamically.

Syntax

<script> Script Contents... </script>

Attributes

Attributes

Description

async

It is used to specify the script is executed asynchronously.

crossorigin

It is used for loading an external script into their domain from a third-party server or another domain with the support of HTTP CORS Request.

defer

It is used to specify that the script is executed when the page has finished parsing.

integrity

It is used to give permission to the Browser to check the fetched script to make ensure the source code is never loaded.

nomodule

It indicates that the script should not execute in the browsers that support ES module. It is a boolean attribute.

nonce

It is used by Content Security Policy to check whether a given fetch will be allowed to proceed for a given element or not.

referrerpolicy

It is used to specify the reference information that will be sent to the server when fetching the script.

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.

Example 1: Add script tag inside the body section of HTML document.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML script Tag</h2>
  
    <p id="GFG"></p>
  
    <!-- HTML script Tag Starts Here -->
    <script>
        document.getElementById("GFG").innerHTML
            = "Hello GeeksforGeeks!";
    </script>
    <!-- HTML Script Tag Ends Here -->
  
</body>
  
</html>


Output: 

script-tag1

Example 2: Add script tag inside the head section of HTML document. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script>
        function Geeks() {
            alert('Welcome to GeeksforGeeks!');
        
    </script>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML script Tag</h2>
  
    <button type="button" onclick="Geeks()">
        Hello GeeksforGeeks
    </button>
</body>
  
</html>


Output: 

sectipt-tag

Supported Browsers 

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 12.1
  • Safari 3

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 19 Oct, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials