How to specify that the target will be downloaded when a user clicks on the hyperlink in HTML?


Use the download attribute to set the file to download on click of the hyperlink. Set the value of the attribute to the name of the downloaded file, for example, image.

Example

<!DOCTYPE html>
<html>
   <body>
      <h3>if statement in Java</h3>
      <p>The following is an image explaining the concept if <b>if-statmement in Java</b> (Click to download):<p>
     
      <a href = "https://www.tutorialspoint.com/java/images/if_statement.jpg" download>
         <img border = "0" src = "https://www.tutorialspoint.com/java/images/if_statement.jpg" alt="Java" width="400" height="450">
      </a>
   </body>
</html>

Updated on: 03-Mar-2020

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements