Tutorialspoint.dev

HTML | script Tag

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:

<!DOCTYPE html>
<html>
    <head>
        <title>script tag</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2><script> Tag</h2>
        <p id="Geeks"></p>
        <script>
            document.getElementById("Geeks").innerHTML = 
                                 "Hello GeeksforGeeks!";
        </script
    </body>
</html>                    

Output:
script tag



Example 2:

<!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

Suppoted Browser: The browser supported by <script> tag are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter