HTML Tags

HTML <script> Tag

The <script> tag is used to embed or reference JavaScript code in an HTML document.
It allows you to create interactive features, handle events, manipulate the DOM, and perform dynamic operations on a webpage.

The <script> tag can be placed in the <head> or <body> section.

Syntax

<script>
  // JavaScript code here
</script>

<!-- OR referencing an external file -->
<script src="script.js"></script>

Attributes

AttributeDescription
srcSpecifies the URL of an external script file.
typeSpecifies the scripting language. Default is text/javascript.
asyncLoads the script asynchronously without blocking HTML parsing.
deferLoads the script after the HTML is fully parsed.
crossoriginHandles CORS requests for external scripts.
nomodulePrevents execution in browsers that support ES modules.

Example

<!DOCTYPE html>
<html>
<head>
  <title>Script Tag Example</title>
  <script>
    function showMessage() {
      alert("Hello! This is a message from JavaScript.");
    }
  </script>
</head>
<body>
  <h1>Click the button to see the message</h1>
  <button onclick="showMessage()">Click Me</button>
</body>
</html>

Output

Browser Output

There is no direct output of the <script> tag itself, but it can add interactivity or dynamically modify page content. Please use our TryIt Editor to see the output.

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

The <script> tag itself is invisible, but it can execute code that displays alerts, modifies content, or responds to user actions.

Notes

  • The <script> tag can contain inline JavaScript or reference an external file.
  • async and defer help improve page load performance.
  • Scripts can be placed in <head> or at the end of <body> for faster rendering.
  • Always ensure scripts are properly secured to prevent XSS vulnerabilities.

Conclusion

The <script> tag is essential for adding dynamic behavior and interactivity to HTML pages.
Although it does not produce visual content directly, it powers most modern web functionality, making it a core element in web development.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend