HTML async Attribute

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The async attribute is used in HTML to indicate that a script should be executed asynchronously as soon as it is available. This attribute can be added to the <script> tag to control the loading and execution of JavaScript files. Unlike the default behavior, where scripts are loaded and executed in the order they appear in the document, causing the parsing of the document to be blocked until the script is downloaded and executed, scripts with the async attribute are executed independently of the page's load process. This means that the page does not wait for the asynchronous script to load and execute, allowing the browser to continue parsing and rendering the rest of the document without interruption.

The async attribute is particularly useful for scripts that do not depend on other scripts and do not modify the DOM (Document Object Model) immediately upon loading. Including the async attribute in a script tag looks like this: <script async src="path/to/script.js"></script>. When a script is loaded with async, it's executed as soon as it is downloaded, which could be before or after the HTML document is fully parsed. This improves the loading performance of web pages but requires developers to be mindful of any dependencies between scripts or on the readiness of the DOM.

Syntax

<script src="URL" async>

Values

  • URLURL or path of the source file.

Applies To

The async attribute can be used on the following html elements.

Example

&lt;script async src="myscript.js"&gt;&lt;/script&gt;

Browser Support

The following table will show you the current browser support for the HTML async Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 28th March 2024