The download attribute on an anchor suggests saving a linked resource instead of opening it as a document.
HTML download links: distinguish a file transfer from page navigation
Use it for a real task
A reviewer exports a CSV for a single authorized receipt. The visible text states the format and record ID, while the filename gives a useful default when the browser honors it. The application must serve the file and set appropriate response headers; markup cannot decide the server's content type, prevent redirects, or grant permission to a private export.
<p>Export only after the review is complete.</p>
<a href="/downloads/receipts/R-47.csv" download="receipt-R-47.csv">
Download receipt R-47 as CSV
</a>What the markup guarantees
The download hint is most predictable for same-origin resources. Browser behavior and server headers can influence the result; test a real response rather than assuming the attribute guarantees a saved file.
Cost and limits
The markup is tiny. The transfer cost is the file itself, and a generated export may consume CPU and storage. Rate limits and authorization belong on the download endpoint.
Common Mistakes
- Do not assume download creates the file.
- Do not expose a private export through an unchecked static route.
- Name the format and record in the visible link text.
Connected lessons
- HTML anchors: use href for navigation and stable fragment targets
- HTML file upload forms: declare multipart encoding and bound the server
- HTML receipt index project: landmarks, links, tables, and a bounded image
Related: HTML object fallback: offer an alternate route to embedded files.
