A link to a PDF or an image often opens in the browser instead of saving. The download attribute asks the browser to save it instead, and it can suggest a better filename than the one in the URL. My advice is to treat it as a hint and set the real name on the server too.
With no value, the browser picks a name. With a value, that is the suggested name:
<a href="/files/report-2026.pdf" download>Download report</a>
<a href="/files/a3f9c1.pdf" download="invoice-november.pdf">Download invoice</a>
It also works with links you build in JavaScript, which is how you let someone save generated text or an image from a canvas:
const blob = new Blob(["hello"], { type: "text/plain" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "hello.txt";
a.click();
URL.revokeObjectURL(a.href);
The catch is that download only works for same-origin URLs, same-origin blob: URLs and data: URLs. For a link to another site the attribute is ignored and the browser just navigates there. So you cannot force a download of someone else’s file with it.
More caveats:
- If the server sends a
Content-Dispositionheader with afilename, that name wins over the attribute. - The browser may still change the name to fit the file system, and slashes are replaced with underscores.
- What happens next depends on the browser and the user’s settings. It may ask, save straight to a folder, or open the file in an app.
Treat the filename as a suggestion and the attribute as a nicety, not as a security feature.
Further reading: MDN: <a> download attribute