HTML async Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Performance & Scripts

Introduction

The async attribute is a valuable feature in HTML that is specifically used with script elements. It controls whether the associated script should be executed asynchronously or not. This attribute can significantly impact the loading and execution behavior of scripts in your web page.

What You’ll Learn

01

Non-Blocking

Parallel download.

02

Boolean Attr

Present = true.

03

External src

Requires src URL.

04

async vs defer

Know the difference.

05

JavaScript

script.async = true

06

Performance

Faster page loads.

Purpose of async

The primary purpose of the async attribute is to influence the way scripts are loaded and executed. When the async attribute is present, it allows the script to be downloaded asynchronously, meaning it won’t block the parsing of the rest of the page. This is particularly useful for non-essential scripts that don’t depend on the page structure.

💡
External Scripts Only

async applies to <script src="..."> elements. It does not affect inline scripts without a src attribute.

📝 Syntax

Add the boolean async attribute to an external script tag:

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

Syntax Rules

  • Boolean attribute — write async alone; presence means true.
  • Requires a src attribute pointing to an external file.
  • Do not use both async and defer on the same script (defer is ignored if async is present).
  • Execution order among multiple async scripts is not guaranteed.

💎 Values

The async attribute has a boolean value, and it can be set to either:

  • true — The script is downloaded in parallel and executed as soon as it is ready. In HTML, simply include the async attribute.
  • false (default) — If the attribute is not present, the script blocks HTML parsing while downloading (unless defer is used).
async-values.html
<!-- Enabled (recommended HTML syntax) -->
<script async src="analytics.js"></script>

<!-- Also valid but redundant -->
<script async="async" src="analytics.js"></script>

<!-- Default: no async -->
<script src="app.js"></script>

⚡ Quick Reference

Loading ModeDownloadExecuteOrder
asyncParallelWhen readyNot guaranteed
deferParallelAfter HTML parsedPreserved
(default)Blocks parsingImmediatelyPreserved
Best forAnalytics, ads, independent widgets
Applicable element<script src="...">

Applicable Elements

ElementSupported?Notes
<script src="...">YesPrimary and only standard use
<script> (inline)No effectasync ignored without src
<link>NoUse preload hints instead
<img>NoUse loading="lazy" for images

Examples Gallery

Basic async scripts, dynamic JavaScript loading, and async vs defer comparison.

👀 Live Preview

A typical async script tag in HTML:

<script async src="analytics.js"></script>

The browser downloads and runs the script without blocking HTML parsing.

Example

Here’s a simple example of how to use the async attribute in an HTML script element:

async.html
<script async src="myscript.js"></script>
Try It Yourself

How It Works

In this example, the async attribute indicates that the script myscript.js should be loaded and executed asynchronously. HTML parsing continues while the file downloads.

Dynamic Values with JavaScript

Similar to other HTML attributes, you can also dynamically set the async attribute using JavaScript. This can be useful when you need to change the loading behavior of scripts based on certain conditions or user interactions. Here’s a brief example:

dynamic-async.html
<script>
  var scriptElement = document.createElement("script");
  scriptElement.src = "dynamicScript.js";
  scriptElement.async = true;
  document.head.appendChild(scriptElement);
</script>
Try It Yourself

How It Works

In this script, a new script element is created dynamically, and the async property is set to true before appending it to the head of the document. This allows dynamicScript.js to be loaded asynchronously.

Example — async vs defer

Choose the right loading strategy for your scripts:

async-defer.html
<!-- Independent analytics: async -->
<script async src="analytics.js"></script>

<!-- App logic that needs DOM: defer -->
<script defer src="app.js"></script>
Try It Yourself

How It Works

Use async for standalone scripts that do not depend on other scripts or DOM readiness. Use defer when scripts must run in order after the document is parsed.

♿ Accessibility

  • Faster first paint — Non-blocking scripts can help content appear sooner for all users.
  • Do not delay critical UI — Async scripts may run mid-interaction; avoid modifying focus without user action.
  • Ensure functionality without JS — Core content should work even if async scripts fail to load.
  • Test keyboard flows — Scripts that inject UI asynchronously should manage focus properly.

🧠 How async Works

1

Browser encounters script

Parser finds <script async src="...">.

Parse
2

Download runs in parallel

HTML parsing continues while the file fetches.

Fetch
3

Script executes when ready

Parsing may pause briefly during execution.

Run
=

Faster initial render

The page becomes interactive sooner while independent scripts load.

Browser Support

The async attribute is supported in all modern browsers on external script elements.

HTML5 · Fully supported

Universal async script loading

All major browsers honor async on <script src> elements.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 10+ supported
Full support
Opera Fully supported
Full support
async attribute 99% supported

Bottom line: Use async confidently on external scripts in all modern browsers.

💡 Best Practices

✅ Do

  • Use async for independent scripts (analytics, ads)
  • Always include a src attribute
  • Test page behavior with slow network throttling
  • Use defer when scripts depend on each other
  • Place critical app logic in deferred or bundled scripts

❌ Don’t

  • Use async on scripts that must run in a specific order
  • Apply async to inline scripts expecting an effect
  • Combine async and defer on the same tag
  • Load DOM-dependent code with async
  • Assume async scripts run before user interaction begins

Conclusion

The async attribute is a powerful tool for optimizing the loading and execution of scripts in HTML. By understanding how and when to use this attribute, you can improve the performance and user experience of your web pages.

Reach for async when scripts are self-contained. When order or DOM readiness matters, choose defer or place scripts at the end of the body instead.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about async

Bookmark these before adding scripts to your page.

5
Core concepts
📄 02

Boolean

Presence = true.

Syntax
🔗 03

Needs src

External only.

Scope
04

vs defer

Order differs.

Compare
⚙️ 05

script.async

Dynamic load.

JS

❓ Frequently Asked Questions

It downloads external scripts in parallel with HTML parsing and executes them as soon as they are ready.
The <script> element with an external src attribute.
async runs when ready (order not guaranteed). defer waits until HTML is parsed and keeps script order.
No. Only external scripts with a src attribute are affected.
Yes. Set scriptElement.async = true on dynamically created script elements.
Yes in all modern browsers. IE 10+ also supports async on external scripts.

Load scripts without blocking your page

Practice the async attribute with external and dynamic script examples in the Try It editor.

Try async script example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful