CodeSource code example

Using HTML Tag For Direct Download


We will learn how to use an HTML tag (the <a> tag) to directly download the file.

As we already know that the <a /> tag is used for a navigation link. As example, if we tried to locate user to some image, the code would be like this:

<a href="/folder/myImage.jpg">My Link</a>

We can use this tag to directly download the file that placed inside href attribute. To do that, simply put download as a attribute inside that tag:

<a href="/folder/myImage.jpg" download>My Link</a>

Note: the href should contain a link to the file. If not, it will just work as a navigation link.


Share on social media

//