Beginner LevelHTML & Semantic Web
How does the anchor download attribute trigger file downloads?
❓ Interview Prompt: Explain anchor download attribute, specifying custom download filenames, and same-origin security restrictions.
Adding the 'download' attribute to an anchor tag instructs the browser to download the linked resource as a file attachment rather than navigating to it.
Custom Filename:
Setting 'download="custom-name.pdf"' renames the downloaded file attachment.
Security Note: The 'download' attribute only works for same-origin URLs or 'blob:'/'data:' schemes.
Code Implementation Example
html
<!-- Force browser file download with custom filename -->
<a href="/docs/report-2026.pdf" download="Annual-Report.pdf">Download PDF Report</a>💡Triggering file download with custom filename via anchor download attribute.
🎯 Interview Key Takeaway
Use the anchor download attribute to force browser file downloads with optional custom attachment filenames.
#download attribute#Anchors#File Download#Beginner
Back to all HTML & Semantic Web Questions→