English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete List of HTML Tags

HTML: <script> async attribute

The async attribute is a boolean attribute. If the async attribute exists, it specifies that the script will be executed asynchronously as soon as it is available. The async attribute is only applicable to external scripts (it should only be used when the src attribute exists).

 HTML <script> tag

Online Example

If the script is executable, it will run asynchronously:

<!DOCTYPE html
<html
<head
<title>HTML: <script> async attribute - Basic Tutorial Website (oldtoolbag.com)<//title>
</head>
<body
<p id="p1">Hello World!<//p>
<script src="demo_async.js" async></script>
</body>
</html>
Test to see ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10Firefox, Opera, Chrome, and Safari support the async attribute.

Note:Internet Explorer 9 and earlier versions do not support the async attribute of the <script> tag.

Definition and Usage

The async attribute is a boolean attribute.

If present, it specifies that the script will be executed asynchronously as soon as it is available.

Note: The async attribute is only applicable to external scripts (it should only be used when the src attribute exists).

Note: External scripts can be executed in multiple ways:

  • If there is asynchronous: the script is executed asynchronously with the rest of the page (the script will execute while the page continues to parse)

  • If there is no asynchronous and there is a delay: execute the script after the page is parsed

  • If there is no asynchronous or delay: immediately fetch and execute the script before the browser continues parsing the page

HTML 4.01 versus HTML5differences

The async attribute is in HTML5 with the added attributes.

Differences between HTML and XHTML

In XHTML, attribute shorthand is prohibited, the async attribute must be defined as <script async="async">.

Syntax

<script async>
 HTML <script> tag