What is the purpose of the download attribute in an anchor tag?
By GetItFully••5 min read

Here is a clear explanation with example code 👇
✅ Purpose of the download Attribute in an Anchor (<a>) Tag
The download attribute in an <a> tag tells the browser to download the file instead of opening it in the browser.
🔹 What it does:
- Forces the linked file (image, PDF, text, etc.) to download.
- Allows you to define the file name for the downloaded file.
- Prevents the browser from displaying the file preview.
✅ Basic Example
<a href="example.pdf" download>Download PDF</a>
JavaScript✔ Clicking this link will download example.pdf instead of opening it in the browser.
✅ Example With Custom File Name
<a href="report.pdf" download="MyReport.pdf">Download Report</a>
JavaScript✔ The file will download as MyReport.pdf, even though the actual file name is report.pdf.
✅ Downloading an Image File
<a href="photo.jpg" download="holiday-photo.jpg">Download Image</a>
JavaScript✔ Image will be downloaded instead of previewing.





