How to force fully download txt file on link?

Download file when clicking on the link (instead of navigating to the file):

<a href="" download>Click here</a>

Download file and rename it to mytextdocument.txt:

<a href="" download="mytextdocument">Click here</a>

The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink.

This attribute is only used if the href attribute is set.

The value of the attribute will be the name of the downloaded file. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).

If the value is omitted, the original filename is used.

Leave a Comment