Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #312

download Attribute

The download attribute on <a> tells the browser to download the linked file instead of navigating to or displaying it.

Syntax

<a href="/files/resume.pdf" download>Download Resume</a>
<a href="/files/resume.pdf" download="Aman-Resume.pdf">Download Resume</a>

Basic Example

<a href="/downloads/course-brochure.pdf" download>
    Download Course Brochure (PDF)
</a>

Browser output: instead of opening the PDF in a new tab or the browser's built-in PDF viewer, clicking triggers a file save/download prompt straight away.

How It Works

  1. Without download, clicking a link to a PDF or image typically opens it directly in the browser.
  2. Adding download overrides that — the browser saves the file to disk instead.
  3. Giving download a value (like download="Aman-Resume.pdf") sets the suggested filename the browser offers when saving, regardless of the file's actual name on the server.

Important Attributes

AttributePurpose
downloadForces a download; an optional value sets the suggested saved filename
hrefMust point to the actual file being downloaded

Real-World Example

<ul>
    <li><a href="/syllabus/data-science.pdf" download>Data Science Syllabus (PDF, 1.2MB)</a></li>
    <li><a href="/syllabus/full-stack.pdf" download>Full Stack Syllabus (PDF, 980KB)</a></li>
</ul>

A resources page offering syllabus PDFs as direct downloads — exactly the kind of link where forcing a download (instead of opening a new tab) is genuinely the better experience.

Common Mistakes

  • Expecting download to work reliably on a cross-origin link (a file hosted on a different domain) — most browsers ignore the attribute in that case for security reasons, and simply navigate to the file instead
  • Forgetting that download only applies to <a> elements — it has no effect if mistakenly placed on other tags
  • Not indicating file type or size in the link text, leaving visitors to guess what they're about to download

Best Practices

  • Only rely on download for same-origin files (hosted on your own domain)
  • Clearly state the file type and, where helpful, its approximate size in the link text
  • Use the value form (download="filename.pdf") when you want a cleaner suggested filename than the one on the server

Accessibility Considerations

Announce that a link triggers a download, not navigation, directly in its text — "Download Resume (PDF)" sets clear expectations for all users, including those on screen readers who won't see a file-type icon.

SEO Considerations

No direct ranking effect, though downloadable resources (guides, syllabi, brochures) can be a genuine source of backlinks and engagement when they're genuinely useful.

Browser & Modern HTML Notes

Well-supported in all modern browsers for same-origin files; cross-origin behavior is intentionally restricted as a security measure and depends on the destination server's CORS configuration.

Mini Practice

  1. Add a download link for a same-origin PDF, including its file type and size in the link text.
  2. Give that download link a custom suggested filename using download="...".

Module 3 Practice Lab

Quick Practice

Build a "Contact & Resources" section with one internal link, one external link (with rel="noopener"), one mailto: link, and one tel: link.

Challenge

Audit a sample navigation menu that uses target="_blank" on every link (including internal ones) and fix it — only the genuinely external link should open in a new tab, with the correct rel value.

Mini Project — Resource Download Page

Build a "Free Resources" page listing three downloadable PDFs using the download attribute, an external link to a relevant outside article (properly secured with rel="noopener"), an internal link back to the homepage, and a footer with both a mailto: and a tel: contact link.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →