Open In App
Related Articles

HTML | <script> async Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

The HTML,<script> async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously when it is available. This attribute only works for external scripts (and used only in when src attribute is present ).
Note: There are so many ways in which external script execute: 
 

  • when async is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)
  • when async is not present and defer is present: The script is executed when the page has finished parsing
  • If neither async or defer is present: The script is fetched and executed immediately before the browser continues parsing the page

Syntax: 
 

<script async>

Example: Index.html 
 

html




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color:green">
          Geeksforgeeks
      </h1>
        <p id="p1">Hello GFG</p>
 
 
        <script src="geeks.js" async></script>
    </center>
</body>
 
</html>


geeks.js 
 

javascript




alert("Hello GFG"); 


Output: 
 

Supported Browsers: The browsers supported by HTML <script> async attribute are listed below 
 

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

 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 02 Jun, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials