What an image link is and why you need it
An image link is a picture that acts like a clickable button — when someone clicks it, they go to a different page or website. Instead of text that says "Click here", you use an image. This is how you turn a logo, photo, or icon into something that takes visitors somewhere else on your site or to an external URL.
The HTML code is straightforward: you wrap an image tag inside a link tag. The link tag tells the browser where to send the visitor, and the image tag tells it what picture to display. You do not need any special software or plugins — just plain HTML in your page code.
Key Takeaways
- An image link combines two HTML tags: the anchor tag (which creates the link) wrapped around the image tag (which displays the picture).
- The basic structure is <a href="destination"><img src="image.jpg" alt="description"></a>, where you replace the parts in quotes with your own URL and image file.
- Always include an alt attribute on the image so screen readers and search engines understand what the picture shows.
- Test the link in your browser after adding it to make sure it points to the right place and the image displays correctly.
The basic HTML structure for an image link
The code has two main parts: an anchor tag (the <a> tag) that creates the link, and an image tag (the <img> tag) nested inside it. Here is the simplest working example:
<a href="https://example.com"><img src="image.jpg" alt="Description of image"></a>
Break this down: the href attribute in the anchor tag holds the URL where you want to send the visitor. The src attribute in the image tag points to the image file itself. The alt attribute describes what the image shows — this text appears if the image fails to load, and it helps screen readers tell visitors what they are clicking on.
The order matters: the <a> tag opens first, the <img> tag sits inside it, and then both close in reverse order. If you reverse the closing tags, the browser will not recognize the link properly.
How to find and prepare your image file
Before you write the code, you need to know where your image file lives. If the image is in the same folder as your HTML file, you can use just the filename: src="logo.jpg". If it is in a subfolder called images, use src="images/logo.jpg". If the image is hosted on a different website, use the full URL: src="https://example.com/images/logo.jpg".
Common image formats that work in HTML are JPG, PNG, GIF, and WebP. JPG works well for photographs. PNG works well for logos and graphics because it supports transparent backgrounds. Make sure your image file name has no spaces — use hyphens or underscores instead, like my-logo.jpg rather than my logo.jpg.
If you are linking to an external image (one hosted on another website), check that you have permission to use it. Some websites block images from being displayed on other sites, and using someone else's image without permission can create legal problems.
Adding width and height to control image size
By default, an image displays at its full size. If your image is very large, it might stretch across the whole page. You can control how big it appears by adding width and height attributes to the image tag:
<a href="https://example.com"><img src="image.jpg" alt="Description" width="200" height="150"></a>
The numbers represent pixels. If you set only the width, most browsers will automatically adjust the height to keep the image from looking stretched or squashed. If you set both, make sure they match the image's original proportions — if the original is 800 pixels wide and 600 pixels tall, use 200 and 150 to keep that same 4:3 ratio.
You can also use CSS to style the image, adding borders, shadows, or hover effects that change how it looks when someone moves their mouse over it. That is a more advanced technique, but it makes image links feel more interactive and polished.
Testing your image link in a browser
After you add the code to your HTML file, save the file and open it in a web browser. Look for the image on the page — if you see a broken image icon (usually a picture frame with an X), the browser cannot find the image file. Check that the filename in the src attribute matches exactly, including capitalization and file extension.
Click on the image. It should take you to the URL in the href attribute. If nothing happens, check that the URL is complete and correct. If you are linking to another page on your own site, make sure the path is right — for example, href="pages/about.html" if the page is in a subfolder called pages.
Right-click on the image and look for an "Inspect" or "Inspect Element" option (available in most modern browsers). This opens the browser's developer tools and shows you the actual HTML code the browser is reading. If the code looks different from what you typed, you may have a typo or formatting error.
Common mistakes and how to fix them
The most frequent error is a broken image path. If you type src="logo.jpg" but the file is actually in a subfolder, the browser will not find it. Always check that the path matches where the file actually sits on your server or in your project folder.
Another common mistake is forgetting the closing </a> tag. Without it, everything after the image becomes a link, which is usually not what you want. Use a code editor that highlights matching tags — it will show you instantly if you are missing a closing tag.
Some people also forget the alt attribute. While the page will still work without it, the link becomes less accessible to people using screen readers, and search engines have less information about what the image shows. Always include it, even if it is just a short phrase like alt="Home page".
If the image appears but the link does not work, double-check the href URL. Make sure it starts with http:// or https:// if it is an external link. If you are linking to another page on your own site, use a relative path like href="about.html" or href="pages/contact.html".
Making image links look clickable
By default, browsers add a blue border around image links to show they are clickable. If you want to remove that border or change how the link looks, you can use CSS. Adding style="border: none;" to the image tag removes the border:
<a href="https://example.com"><img src="image.jpg" alt="Description" style="border: none;"></a>
You can also add a hover effect so the image changes when someone moves their mouse over it. This requires a bit more CSS, but it signals to visitors that the image is interactive. For example, you could make the image slightly transparent or add a shadow when the cursor hovers over it.
Keep in mind that removing the border entirely can make it unclear that the image is a link. If you remove it, consider adding a visual cue elsewhere — like a caption that says "Click to learn more" or styling the image with a subtle background color or outline.
Frequently Asked Questions
Can I make an image link to an email address?
Yes. Use href="mailto:your-email@example.com" instead of a regular URL. When someone clicks the image, their default email program will open with a new message addressed to that email. You can also add a subject line: href="mailto:your-email@example.com?subject=Hello".
What if my image is very large and slows down the page?
Resize the image file itself using an image editor before you add it to your page. You can also use CSS to display it smaller on the page, but that does not reduce the file size the browser has to download. Smaller file sizes mean faster loading, which improves the experience for visitors on slower connections.
Can I use an image as a link to open a file instead of a webpage?
Yes. Use the file path in the href attribute, like href="documents/resume.pdf". When someone clicks the image, the browser will either display the file or prompt them to download it, depending on the file type and browser settings.
How do I make an image link open in a new tab?
Add target="_blank" to the anchor tag: <a href="https://example.com" target="_blank"><img src="image.jpg" alt="Description"></a>. This tells the browser to open the link in a new tab instead of replacing the current page.
Do image links affect my search engine ranking?
Search engines can follow image links the same way they follow text links. The alt attribute helps search engines understand what the image shows, so including descriptive alt text is useful for both accessibility and search visibility.