async

The async attribute in HTML allows scripts to load and execute asynchronously, enabling faster page loading.

async attribute

The async attribute in HTML instructs the browser to load and execute a script asynchronously, meaning it won’t block the page from loading.

Syntax

index.html
<script src="URL" async>

Example

::atter-async ::
index.html
<script id="el" src="/example.js" async></script>
The async attribute is used in the <script> tag to indicate that the script should load and execute independently of the page's parsing process. This allows the browser to continue rendering the document without waiting for the script to complete.

Values

  • The URL or file path of the script.

Applies To

The async attribute is applicable to the following HTML element:

Example

index.html
<script async src="myscript.js"></script>

Conclusion

The async attribute enhances webpage performance by allowing scripts to load and execute without delaying HTML parsing. When used in the <script> tag, it prevents scripts from blocking page rendering, resulting in faster page loads. However, since async scripts execute as soon as they are available, developers should ensure that dependencies are not affected.