HTML Image Links

HTML image links allow you to make an image clickable. When a user clicks the image, the browser opens the webpage or resource specified by the link. You can create an image link by placing the HTML <img> tag inside an anchor (<a>) element.

Image links are commonly used for website logos, product images, banners, photo galleries, and navigation menus. They help users navigate between webpages using images instead of text.

How to Create an HTML Image Link

To create an image link, place the <img> element inside the <a> element. The href attribute specifies the destination, while the src attribute specifies the image file.

HTML Image Link Syntax

<a href="https://example.com">
    <img src="image.jpg" alt="Visit Example Website">
</a>

In this example, clicking the image opens the website specified in the href attribute.

HTML Image Link Example

The following example demonstrates how to create a clickable image using HTML.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Image Links</title>
</head>
<body>

    <h1>HTML Image Links</h1>

    <a href="https://www.example.com">
        <img src="flower.jpg"
             alt="Visit Example Website"
             width="300">
    </a>

</body>
</html>

Save this code as index.html and place flower.jpg in the same folder. When users click the image, the browser navigates to the specified destination.

Opening an Image Link in a New Tab

You can use the target="_blank" attribute to open the linked webpage in a new browser tab.

<a href="https://www.example.com" target="_blank" rel="noopener">
    <img src="flower.jpg"
         alt="Visit Example Website"
         width="300">
</a>

Here, target="_blank" opens the destination in a new tab. The rel="noopener" attribute prevents the newly opened page from accessing the original page through window.opener.

HTML Image Links Using Local Files

You can also link an image to another HTML file within your website.

<a href="about.html">
    <img src="logo.png" alt="Visit the About page" width="150">
</a>

When a user clicks the logo, the browser opens about.html. This technique is useful for website logos, navigation systems, and image-based menus.

HTML Image Links vs Normal Links

FeatureImage LinkText Link
Clickable elementAn imageText
HTML element<img> inside <a>Text inside <a>
DestinationDefined by hrefDefined by href
AccessibilityRequires meaningful image alternative textUses descriptive link text
Common usesLogos, banners, product imagesNavigation, articles, references

Both types of links use the anchor element to specify their destination.

Related HTML Tutorials

Continue learning HTML with these published tutorials on Web4learners: