Home HTML HTML script Tag with Example

HTML script Tag with Example

12
0

HTML <script> tag represents client-side scripts like JavaScript, jQuery.

The script tag is generally used to handle some client-side events to take some actions or validations like validate email address, password length, passwords comparison etc. It is also used to link some external scripts like JavaScript, jQuery using src attribute of script tag.

The script tag can be used inside HTML <head> tag that is used to represent the head section for web page or <body> tag that is used to represent visible body content for web page.

Note: The <script> tag is mostly supported in all major web browsers.

HTML script Tag Sample Code

<html>
<head>
    <title>HTML/HTML5 script Tag with Example</title>
    <!--Following statements are invisible for web page but 
        when user action occurs, scripts will called-->

    <!--To link an external scripts-->
    <script type="text/javascript" src="jqury.js"></script>
    <script type="text/javascript" src="script.js"></script>

    <!--Javascript functions or statements-->
    <script type="text/javascript">
        function alertMessage() {
            alert('Some text when this script called!!');
        }
    </script>
</head>
<body>
    <p>Visible script related page content starts here</p>
    <script type="text/javascript">
        document.write("HTML script tag example in body tag");
    </script>
</body>
</html>

HTML script Tag Sample Result

Visible script related page content starts here

Note: scripts inside body tag usually written at the end of the body tag.You can see the complete List of HTML Elements here.

Tag Specific Attributes Support

Following are script tag attributes that are supported by <script> tag.

Attribute Value Description
src url Represents the source path to link external scripts
type text/javascript Represents the type of the script

Standard Attributes Support

HTML <script> tag does not support HTML Attributes. But you can get more details about available HTML Attributes here.

Event Attributes Support

HTML <script> tag does not support Event Attributes. But you can get more details about available HTML Event Attributes here.

Previous articleHTML samp Tag with Example
Next articleHTML section Tag with Example
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

two × 5 =