You can use an image as a link in HTML by wrapping the <img>
tag with an <a>
tag. This allows the user to click on the image and be redirected to a different page or location.
Here is an example of how to create an image link:
<a href="https://www.example.com">
<img src="example.jpg" alt="Example Image">
</a>
In this example, the image is wrapped in an anchor tag (<a>
) with the href
attribute set to the destination URL. When the user clicks on the image, the browser will navigate to the URL specified in the href
attribute.
You can style the image link using CSS, just like any other HTML element. For example, you can add a border around the image to make it more prominent, like this:
<a href="https://www.example.com">
<img src="example.jpg" alt="Example Image" style="border: 2px solid red;">
</a>
In this example, the style
attribute is used to apply a 2-pixel solid red border around the image.