How to Create an HTML Download Link?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Downloading files refers to receiving information from a server so that later on it can be viewed offline. Millions of downloads take place every day. A download link on a website is used to download a specific file when the user clicks on it. The anchor <a> tag along with its href and download attributes assist in implementing this feature. The file to be downloaded can be a pdf, zip, jpg, png, doc, etc.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax

Download Restrictions

The download attribute works for same-origin URLs, that is only files that belong to that website can be downloaded. In simple terms, if href does not have the same origin as the site, the file won't be downloaded.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

What is the Same-Origin Policy?

The same-origin policy is a security mechanism that removes documents that might cause cyber threats. The policy helps users to download only those files that are from the origin site.

same-origin policy

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

HTML download link is created using the <a> tag. The value of the href property is set to the location of the file to be downloaded, and a download attribute is added. The new filename of the downloaded file can be set as the value for the download attribute. The original filename is used if no value is specified.

Code

original file name links with black bg

The property supports all file extensions, and the browser detects it (.img, .pdf, .txt, .html, etc.).

Users can right-click on the link and choose 'Save As' from the list of options to download the file to their local system.

Note: Before creating the download link, ensure that the file is uploaded to the specified location.

ZIP File Download Link

MP3 File Download Link

PDF File Download Link

Browser Support

HTML download link is supported by the following browsers.

  • Google Chrome
  • Firefox
  • Microsoft Edge
  • Safari
  • Opera

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Learn more

Conclusion

  • A download link helps to download a file from the server to the browser's directory on the local disk.
  • The download attribute is used after the href attribute, to make the link downloadable.
  • If a value is assigned to the download attribute, it becomes the new filename of the downloaded file. The original filename is used if no value is specified.
  • There are no restrictions on the file extension type of the file to be downloaded (.img, .pdf, .txt, .html, etc.).
  • The download attribute ensures security by permitting only same-origin URLs, that is only files that belong to that website can be downloaded.