HTML download Attribute

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

Definition and Usage

The download attribute on an <a> or <area> with an href tells the browser to download the linked resource instead of navigating to it. An optional value suggests the saved filename.

Without a value, the browser picks a name from Content-Disposition, the URL path, or the media type. With a value like guide.pdf, that name is suggested (slashes become underscores). Say in the link text that a download will start.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015. Same-origin rules still limit when a custom filename is honored.

Same-origin only (plus blob: / data:).

Cross-origin href values usually ignore download and navigate instead. The remote server can still force a save via Content-Disposition.

HTML Syntax

syntax.html
<a href="url"  download>

Optional filename: download="report.pdf". Empty download or download="" still requests a download with a default name. In JavaScript: link.download = "report.pdf".

Attribute Values

Optional filename string — presence alone is enough to request a download:

ValueDescriptionTry it
download (empty)Download using a default name from headers, URL, or typeTry it
download="name.ext"Suggest that filename (include the extension)Try it
blob: / data:Works with generated files; set link.download in JSTry it
Cross-origin URLAttribute usually ignored — normal navigation—

Live Preview

Change how download is set on a same-origin data: link, then click the link to save a tiny text file.

Uses a data: URL so the download works without a server file.

Link

Download notes.txt

download = "notes.txt"

HTML Examples

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

Example 1 — Custom Download Filename

Suggest a clear name when saving a same-origin file.

HTML
<a href="/files/honey-bee.pdf" download="honey-bee-guide.pdf">
  Download PDF (honey-bee-guide.pdf)
</a>
Try It Yourself

How It Works

  1. href points at the file to fetch (same origin).
  2. download="…" suggests the saved filename.
  3. Click starts a download instead of opening the PDF in a tab (when honored).
  4. Link text names the file so users know a download will start.

Example 2 — Downloadable Image

Wrap an image so clicking it saves the file.

HTML
<a href="/images/javascript.png" download="javascript-logo.png">
  <img src="/images/javascript.png" alt="Download JavaScript logo" width="96" height="96">
</a>
Try It Yourself

How It Works

  1. Anchor wraps the <img> — the link carries download.
  2. href is the image URL to save.
  3. alt explains the purpose for screen readers.
  4. Click downloads instead of navigating to the image alone.

Example 3 — data URL and JavaScript

Generate content in the page and set the filename in script.

HTML
<a id="save" href="data:text/plain,Hello%20World!">Download text file</a>

<script>
  document.getElementById("save").download = "generated_file.txt";
</script>
Try It Yourself

How It Works

  1. href holds a data: (or blob:) URL with the file bytes.
  2. JavaScript sets HTMLAnchorElement.download to the filename.
  3. Click saves that content under the suggested name.
  4. Useful for exports, canvas images, and client-side reports.

Edge Cases & Pitfalls

Most surprises come from origin rules, HTTP headers, or unclear link text.

origin

Cross-origin ignores download

For other sites, the attribute is ignored and the browser navigates. Use same-origin files, or let the server send Content-Disposition: attachment.

headers

Content-Disposition can win

download overrides inline, but a header filename overrides the attribute’s suggested name.

name

Filename, not a path

Use report.pdf, not /files/report.pdf. Characters like / and \ become underscores.

a11y

Announce the download

Link text (or image alt) should say a file will download — unexpected saves confuse keyboard and screen-reader users.

ux

Browser settings vary

Users may get a prompt, auto-save, or open-in-app. You cannot fully control that from HTML alone.

Browser Support

download is an HTML attribute on links in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

download

Supported in modern Chrome, Firefox, Safari, and Edge. Custom filenames require same-origin (or blob:/data:) URLs; cross-origin behavior differs by browser.

96% Global support (approx.)
Google Chrome 14+
Full support
Mozilla Firefox 20+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 13+
Full support
Opera 15+
Full support
Samsung Internet Modern
Full support
Internet Explorer —
Not supported
download Widely supported

Bottom line: Safe for modern sites. Always plan for same-origin (or blob/data) when you need a reliable custom filename.

Key Takeaways

  • On <a> / <area>: download instead of navigate; optional filename.
  • Same-origin (plus blob: / data:) for the attribute to apply.
  • JS: link.download = "name.ext" for dynamic exports.
  • A11y: say in the link text that a file will download.

One line: download saves the linked file (same-origin) and can suggest the filename.

Frequently Asked Questions

On an a or area element with an href, download tells the browser to download the linked resource instead of navigating to it. An optional value suggests the saved filename.
Only a and area elements that have a valid href. It does not apply to button, img, or other tags by themselves.
Yes. Set download to a filename such as report.pdf. Use a name with an extension, not a full URL path. Slashes are turned into underscores.
No for the attribute itself. Browsers honor download for same-origin URLs, and for blob: and data: URLs. Cross-origin links usually navigate instead; the server may still force a download with Content-Disposition.
When download is honored, it overrides Content-Disposition: inline. But a Content-Disposition filename parameter overrides the name you put in the download attribute.
Yes. Use link.download = "filename.ext" on an HTMLAnchorElement. This pairs well with blob: and data: URLs for generated files.

Next: draggable

Hint whether an element can be dragged with the mouse or pointer.

draggable tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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