Download Button
A download button is a hyperlink styled as a button that points to a downloadable file. It uses an <a> element (not <button>) so that users can right-click and "Save link as…", and so that the native download attribute can suggest a filename.
Use it for prominent download calls-to-action such as installer downloads, PDF reports, datasets, exported files, and signed asset bundles.
Implementation Notes
- Uses an
<a>element so right-click "Save link as" works and thedownloadattribute can apply hrefis required — the URL of the filelabelis required — setsaria-labelso the accessible name reflects the download intentfileSizeandfileFormatare surfaced asdata-file-sizeanddata-file-formatfor consumer stylingdownloadbooleantruerenders baredownload(browser-suggested filename); a string sets the suggested filename- Children render the visible button content; defaults to
labelwhen omitted
Props
href: string (required) -- file URLlabel: string (required) -- aria-label and default visible textfileSize: string (optional) -- pre-formatted size text (e.g., "2.4 MB")fileFormat: string (optional) -- file format text (e.g., "PDF")download: string | boolean (optional) -- native download attributechildren: slot (optional) -- visible button content; defaults tolabel...restProps: any additional HTML attributes
Usage
Basic download link:
<DownloadButton href="/files/report.pdf" label="Download annual report (PDF, 2.4 MB)">
Download report
</DownloadButton>
With download attribute and metadata:
<DownloadButton
href="/files/report.pdf"
label="Download annual report"
fileSize="2.4 MB"
fileFormat="PDF"
download="annual-report-2025.pdf"
>
Download report
</DownloadButton>
Keyboard Interactions
- Tab: Focus the link
- Enter: Activate the link (download or navigate)
- (All handled natively by
<a>element)
ARIA
- Implicit
linkrole from the<a>element aria-labelprovides the descriptive accessible name including download intent (required)data-file-sizeanddata-file-formatare non-ARIA hooks for consumer styling
When to Use
- Use for prominent file downloads (installers, PDFs, datasets) where the action is the primary call to action.
- Use when the user benefits from a suggested filename via the native
downloadattribute. - Use when right-click "Save link as" is desired behavior.
When Not to Use
- Do not use for in-app actions that do not download a file — use Button instead.
- Do not use for cross-origin URLs where the
downloadattribute will be ignored without proper headers. - Do not omit
label— the accessible name should describe what is being downloaded.
Headless
Renders a native <a> element with href, aria-label, optional download, and optional data-* attributes. Visual button styling, file-format icons, and metadata layout are entirely the consumer's responsibility.
Styles
Consumer CSS targets the download-button class. Style it as a button with a clear focus indicator and hover/active feedback. Use the data-file-size and data-file-format attributes to render badges or pseudo-element labels.
Testing
- Verify the component renders an
<a>element with classdownload-button - Verify
hrefis present and equals thehrefprop - Verify
aria-labelis present and equals thelabelprop - Verify
data-file-sizeis rendered whenfileSizeis provided - Verify
data-file-formatis rendered whenfileFormatis provided - Verify
downloadis rendered as bare attribute whendownload={true}and as filename when a string
Advice
- Designers: Make file format and size visible (PDF, 2.4 MB) so users know what they are downloading. Use the same focus and hover treatment as other primary buttons.
- Developers: Pre-format
fileSizein the consumer's locale. Use thedownloadattribute only for same-origin URLs or cross-origin URLs that send appropriateContent-Dispositionheaders.
Related components
button— a generic clickable button elementdocument-list-item— one document entry in a document listfile-input— an input for selecting files from the file system <input type="file">
References
- MDN
<a>download attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download - WAI-ARIA Link Pattern: https://www.w3.org/WAI/ARIA/apg/patterns/link/
- Mozilla Protocol Design System: https://protocol.mozilla.org/