CKTIS / HTML
download: request saving a linked resource
Suggest a filename without assuming authority over browser download policy.
Version: HTML Living Standard
Syntax
<a href="..." download="note.txt">Download</a>On an anchor or image-map link, download indicates an intended download instead of normal navigation. Its optional value suggests a filename. The browser may sanitize that name or use server response information, and user policy can still affect the operation. It does not grant arbitrary writes to the user’s filesystem.
Same-origin resources and locally created blob URLs are the straightforward case. Cross-origin downloads need appropriate server cooperation, including attachment handling; do not treat the attribute alone as permission to force them. Release a temporary object URL after it is no longer needed, not before the download can use it.
The example creates a tiny text blob and a download link. A real click produces a completed download with the suggested filename and exact expected bytes. The page reports only the request; completion is established independently by the browser test.
Examples
<!doctype html><meta charset="utf-8">
<a id="download" download="note.txt">Download local text</a><output id="result"></output><script>
const link = document.querySelector('#download');
const url = URL.createObjectURL(new Blob(['Local example.\n'], { type: 'text/plain' }));
link.href = url;
link.addEventListener('click', () => { document.querySelector('#result').textContent = 'downloadRequested=true'; });
window.addEventListener('pagehide', () => URL.revokeObjectURL(url), { once: true });
</script>Result
downloadRequested=true
The file is generated test text, not a file read from the user’s computer.