Want to add a link to an image? How to make an image clickable? In this tutorial, you will learn how to make an image a link in HTML
Add a link to an image in HTML
The first step is to add an image using the image(<img>) tags. See the below HTML code for reference.
<img src="image.jpg" alt="my image" />
Once you have the image to the HTML document it’s time to add the link such that when clicked, it should open a URL or link.
As stated above, The second step is to wrap the image tag with the anchor tag and give the anchor tag a href attribute to set the link. How to do it? Below is the code snippet for your reference.
<a href="url"> <img src="image.jpg" alt="my image" /> </a>
Make the image clickable and open the link in the new tab
If you want to open the link in a new tab when you click the image, then you need to add the target attribute to the anchor tag.
<a href="url" target="_blank"> <img src="image.jpg" alt="my image" /> </a>
Whether the image is small or big it doesn’t matter, once you wrap the image with the anchor tag the browser treat it as clickable. The whole image works as a button. And you can use this method to make an image clickable.
- Your desired hyperlink to the href= attribute.
- The image source URL or local path to the src= attribute.
- Finally, change the alt text for the image to the alt= attribute.
Hope you were able to make an image a link in HTML successfully. If you face any issues or have any confusion regarding the steps, let us know in the comment. We will definitely help you with the HTML project.