The download attribute on <a> and <area> links tells the browser to download the linked resource instead of opening it in the page. You can optionally set a custom filename so users save files with a clear, descriptive name.
01
Force Download
Save, not navigate.
02
Custom Name
Filename string.
03
a and area
With href only.
04
Same Origin
Security rule.
05
JavaScript
link.download.
06
data / blob
Generated files.
Fundamentals
Purpose of download
Without download, clicking a link to a PDF, image, or other file may open the resource in a new tab instead of saving it. The download attribute prompts the browser’s save dialog and lets you suggest a filename that is clearer than the server path.
This improves user experience when offering templates, reports, images, or exported data. It is especially helpful when the original URL filename is generic (like file?id=42) but you want the saved file to be readable (like invoice-march.pdf).
💡
Filename, not a path
The download value should be a filename such as report.pdf, not a full URL like /files/report.pdf.
Foundation
📝 Syntax
Add download to an anchor with a valid href:
download.html
<ahref="/files/honey-bee.pdf"download="honey-bee-guide.pdf">
Download PDF
</a>
Syntax Rules
Only valid on <a> and <area> elements with an href.
Optional string value suggests the saved filename (include the extension).
Empty download or download="" still forces download with a default name.
Same-origin URLs are required for reliable custom filenames in most browsers.
Reference
💎 Values
The download attribute accepts an optional filename string:
download="my_document.pdf" — Save as my_document.pdf.
download="photo.png" — Save an image with a custom name.
download (no value) — Download with the resource’s default filename.
JavaScript can set download on links pointing to data: or blob: URLs created at runtime.
A11y
♿ Accessibility
Use clear link text — Say “Download PDF report” instead of vague “Click here.”
Indicate file type — Mention format and size when helpful (e.g. PDF, 2 MB).
Do not rely on images alone — If the link wraps an image, provide meaningful alt text.
Warn about large files — Let users know before starting a big download.
🧠 How download Works
1
User clicks link
Anchor with href and download attribute.
Click
2
Browser fetches resource
Same-origin check for custom filename.
Fetch
3
Save dialog appears
Suggested filename from download value.
Save
=
📥
File saved locally
User gets the file without leaving your page.
Compatibility
Browser Support
The download attribute is supported in all modern browsers. Same-origin restrictions apply consistently across engines.
✓ HTML5 · Fully supported
Download links in modern browsers
Chrome, Firefox, Safari, and Edge support download on a and area elements.
97%Browser support
Google ChromeFully supported
Full support
Mozilla FirefoxFully supported
Full support
Apple SafariFully supported
Full support
Microsoft EdgeFully supported
Full support
download attribute97% supported
Bottom line: Use download for same-origin files; test cross-origin behavior separately.
Pro Tips
💡 Best Practices
✅ Do
Use descriptive filenames with extensions
Host downloadable files on the same origin
Wrap images in download links when needed
Use blob URLs for client-generated exports
Tell users what they are downloading
❌ Don’t
Put full paths in the download value
Expect custom names on cross-origin URLs
Use download on elements without href
Hide malicious downloads behind vague link text
Rely on download for HTML pages you want viewed
Wrap Up
Conclusion
The download attribute is a valuable tool for offering files directly from hyperlinks. It turns navigation links into save actions and lets you suggest clear filenames for PDFs, images, exports, and other resources.
Use it on same-origin <a> links, pair descriptive link text with the correct file extension, and set filenames dynamically with JavaScript when generating content at runtime.