Skip to content
AITroveRead. Build. Understand.
Make this comfortable

HTML download links: distinguish a file transfer from page navigation

Last updated: 5 Oct 20267 min read
tutorial
IntermediateBy AITrove Editorial

The download attribute on an anchor suggests saving a linked resource instead of opening it as a document.

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.

html
<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

Related: HTML object fallback: offer an alternate route to embedded files.

html
core
Storage details