Web development

Use a download link for a same-origin file

Use the download attribute to suggest saving a same-origin resource with a chosen filename. It is a browser hint and does not override every server header or cross-origin restriction.

Worked example

HTML example · save as example.html and open in a browser

<a href="/exports/sample.csv" download="sample.csv">Download the sample CSV</a>
<!-- Create /exports/sample.csv on your server before using this link. -->

How it works

The destination identifies the file, and download suggests a local filename. The link text explains both the action and format. Serving a real file with an appropriate content type makes behavior clearer than linking to an endpoint that actually returns an HTML error page.

Limits and mistakes

Cross-origin downloads and Content-Disposition headers can change behavior. The attribute does not create the referenced file. Do not promise a particular phone folder or filename when browser and operating-system choices control the save location.

Check the result

Serve the example file from the same origin, activate the link, and inspect the saved bytes. Check the network response if the result is an error page or opens as a document instead.

Sources

Reference documentation for the behavior used in this guide: