HTML async Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The async attribute on a <script> with src fetches the file in parallel with HTML parsing and runs it as soon as it is available.

It is a boolean attribute. Use it for independent scripts (analytics, ads, widgets). Prefer defer when order matters or the script needs the full DOM. See also type="module".

Baseline · Widely available.

Not deprecated. Stable across modern browsers since about July 2015.

Needs src (classic scripts).

On inline classic scripts, async has no effect. If both async and defer are set, async wins.

HTML Syntax

syntax.html
<script src="file.js"  async></script>

Boolean form: write the name alone. async="" or async="async" means the same thing.

Attribute Values

async is boolean — presence turns the behavior on:

ValueDescriptionTry it
async (present)Fetch in parallel; run as soon as ready. Order not guaranteedTry it
(absent)Default classic script: parser may block until the script loads and runsTry it
vs deferdefer waits until HTML is parsed and keeps document orderTry it
with modulesOn type="module", async fetches the graph early and runs when readyTry it

Live Preview

Load a tiny external script (data URL) with or without async and watch the log order.

Simulates fetch timing with a short delay. Real network order can still vary with async.

Event log

    Mode: async

    HTML Examples

    Short, copy-ready snippets. Use Try It Yourself for a live editor.

    Example 1 — External Script with async

    Download in parallel; run when ready without blocking the HTML fetch.

    HTML
    <h1>Hello</h1>
    <p id="status">Page HTML keeps parsing…</p>
    
    <script async src="data:application/javascript,document.getElementById('status').textContent='Async script ran.'"></script>
    
    <p>This paragraph is still in the HTML stream.</p>
    Try It Yourself

    How It Works

    1. src points at an external script (required for classic async).
    2. async starts the download without pausing the parser for the fetch.
    3. When ready, the script runs (may briefly pause rendering).
    4. No order promise relative to other async scripts.

    Example 2 — async vs defer

    Same download idea — different run time and ordering rules.

    HTML
    <!-- Independent: run ASAP, order not guaranteed -->
    <script async src="analytics.js"></script>
    
    <!-- Needs DOM / order: run after parse, in document order -->
    <script defer src="app.js"></script>
    <script defer src="widgets.js"></script>
    Try It Yourself

    How It Works

    1. Both avoid blocking the HTML download while fetching.
    2. async executes whenever the file arrives.
    3. defer waits until parsing finishes, then runs in order.
    4. Pick defer for app code that touches the DOM or depends on earlier scripts.

    Example 3 — Several Independent async Scripts

    Fine for unrelated files — do not depend on load order between them.

    HTML
    <script async src="ads.js"></script>
    <script async src="analytics.js"></script>
    <script async src="chat-widget.js"></script>
    
    <!-- Risky: script-b may run before jquery -->
    <!-- <script async src="jquery.js"></script> -->
    <!-- <script async src="script-b.js"></script> -->
    Try It Yourself

    How It Works

    1. Each async script races to download on its own.
    2. Whoever finishes first may run first.
    3. Safe when scripts are independent of each other and the DOM.
    4. Unsafe for jQuery + plugins — use defer (or modules) instead.

    Edge Cases & Pitfalls

    Most bugs come from assuming order or putting async on inline scripts.

    src

    Ignored without src

    Classic inline scripts ignore async. Move the code to an external file if you need this behavior.

    order

    No guaranteed execution order

    Do not chain dependent libraries with multiple async tags. Use defer, modules, or a bundle.

    both

    async + defer → async wins

    Spec: if both are present, the element acts as if only async is set.

    DOM

    May run before the DOM is ready

    If the script queries elements below it, prefer defer or wait for DOMContentLoaded.

    modules

    Modules already defer by default

    type="module" defers automatically. async on modules still means “run as soon as the graph is ready.”

    Browser Support

    async is an HTML attribute on <script> in the browser. It is not a Node.js, Deno, or Bun API.

    ✓ Baseline · Widely available

    async

    Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support async on external scripts.

    97% Global support (approx.)
    Google Chrome All modern
    Full support
    Mozilla Firefox All modern
    Full support
    Apple Safari All modern
    Full support
    Microsoft Edge All modern
    Full support
    Opera All modern
    Full support
    Samsung Internet Modern
    Full support
    Internet Explorer 10+
    Supported
    async Widely supported

    Bottom line: Safe to use for independent external scripts. Prefer defer when document order or full DOM access matters.

    Key Takeaways

    • Role: fetch external scripts in parallel; run as soon as ready.
    • Boolean on <script src> — ignored for classic inline scripts.
    • vs defer: async = ASAP + unordered; defer = after parse + ordered.
    • Best for: independent analytics/ads — not dependent app chains.

    One line: async loads scripts early without guaranteed order — use defer when order or the DOM matters.

    Frequently Asked Questions

    On an external script, async fetches the file in parallel with HTML parsing and runs it as soon as it is available. Execution order among multiple async scripts is not guaranteed.
    Yes. Presence means true; absence means false. Writing async="async" or async="" is the same as async.
    Use async for independent scripts (analytics, ads) that do not need DOM order. Use defer when scripts must run in document order after the HTML is parsed.
    No for classic scripts. Without src, async has no effect. Use an external file (or a module script) when you need async behavior.
    The element behaves as if only async is specified (async wins).
    No. It is Baseline widely available and recommended for independent external scripts.

    Next: autocapitalize

    Hint virtual keyboards how to capitalize text input.

    autocapitalize tutorial →

    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.

    8 people found this page helpful