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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
script tag

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
script tag

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

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.