Open In App
Related Articles

HTML script Tag

Improve Article
Improve
Save Article
Save
Like Article
Like

The <script> tag in HTML is used to define the client-side script. The <script> tag contains the scripting statements, or it points to an external script file. The JavaScript is mainly used in form validation, dynamic changes of content, image manipulation, etc.
Syntax: 
 

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

Attributes: Many attribute associated with 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.

Example 1: 
 

HTML




<!DOCTYPE html>
<html>
 
        <body>
 
            <h1>GeeksforGeeks</h1>
            <h2><script> Tag</h2>
            <p id="Geeks"></p>
 
 
            <!-- html script tag starts here -->
            <script>
                document.getElementById("Geeks").innerHTML =
                                     "Hello GeeksforGeeks!";
            </script>   
            <!-- html script tag ends here -->
 
        </body>
 
</html>                   

Output: 
 

Example 2(script outside body tag): 

HTML




<!DOCTYPE html>
<html>
    <head>
        <title>script tag</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
        <script>
            function Geeks() {
                alert('Welcome to GeeksforGeeks!');
            }
        </script>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2><script> Tag</h2>
        <button type="button" onclick="Geeks()">
            Hello GeeksforGeeks</button>
    </body>
</html>                   

Output: 
 

script tag

Supported Browsers: 
 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer
  • Firefox 1 and above
  • Opera
  • Safari

 


Last Updated : 28 Jul, 2022
Like Article
Save Article
Similar Reads