Hyperlink Image HTML: Clickable Image Code (2026)
November 11, 2026 · 10 min read
Hyperlink Image HTML: Make Any Picture a Clickable Link
The hyperlink image HTML you need is short: put an <img> element inside an <a> element, and the link's href decides where a click goes. Give the image alt text that names the destination and set its width and height. The picture then works as a link for mouse, keyboard and screen reader users.
The Basic Hyperlink Image HTML Code
Here's the HTML code to hyperlink an image, with every attribute you should include from the start:
<a href="https://example.com/pricing">
<img src="/images/pricing-card.png" alt="See pricing plans" width="320" height="180">
</a>
The result is a picture at 320 by 180 pixels. Clicking it, or pressing Enter while it has keyboard focus, opens https://example.com/pricing. Nothing else on the page changes, because the <a> element only adds link behaviour around whatever sits inside it.
A quick recap of the <img> attributes, so this snippet stands on its own:
srcis the image file's URL. It can be absolute (https://...) or relative to the current page (/images/pricing-card.png).altis the text alternative. Inside a link, it also becomes the link's name, which the next sections cover.widthandheightare the image's size in pixels. MDN's img reference explains that the browser uses them to work out the aspect ratio and reserve space before the file loads, which reduces layout shift.
And on the link side, href is the only attribute an <a> needs to be a working hyperlink. Everything else is optional. The HTML anchor tag guide covers those optional attributes.
How Do You Create a Link Image in HTML?
Building one from scratch takes four steps:
- Get the image's URL. Use a full
https://address for an image on another site, or a path such asimages/logo.pngfor a file in your own project. - Write the
<img>tag withsrc,alt,widthandheight. - Wrap it in
<a href="...">and</a>, with the destination URL inhref. - Test it twice: click the image, then press Tab until it gets focus and press Enter.
A common source of confusion is the difference between making an image clickable and linking to an image. A plain text link like <a href="/photos/beach.jpg">View the photo</a> opens the image file itself. Making the picture clickable means the image is the link, as in the snippet above.
The same idea answers a question people often ask about JPEG and PNG files. An image file can't hold a hyperlink by itself. The link always lives in the HTML (or Markdown, or email) around the picture, so you add it wherever the image is displayed.
Alt Text for a Linked Image Should Name the Destination
When an image is the only thing inside a link, its alt text is the link's accessible name. A screen reader announces it, and voice control users say it to activate the link. The W3C's WCAG technique H30 says the alt text should describe the link's function, not the picture.
Compare these two versions of a logo that links home:
<a href="/"><img src="/logo.svg" alt="logo" width="120" height="40"></a>
<a href="/"><img src="/logo.svg" alt="Acme home page" width="120" height="40"></a>
The first gives a screen reader user "link, logo", which says nothing about where it goes. The second says "link, Acme home page". Avoid alt="click here" too, and never leave the alt attribute off an image-only link. Without it, screen readers typically fall back to reading out the file name or a URL, which rarely helps.
The rule flips when the link also contains visible text. In the W3C's functional images tutorial, an icon next to link text gets an empty alt="", so the name isn't read twice:
<a href="/docs/install">
<img src="/icons/download.svg" alt="" width="24" height="24">
Install guide
</a>
Here the link's name is "Install guide", and the icon is treated as decoration.
Opening an Image Link in a New Tab with target and rel
The new-tab attributes go on the <a>, never on the <img>. Add target="_blank" to the link and keep rel beside it:
<a href="https://developer.mozilla.org/" target="_blank" rel="noopener">
<img src="/img/mdn-logo.png" alt="MDN Web Docs (opens in a new tab)" width="160" height="40">
</a>
noopener stops the new page from reaching back into your tab through window.opener. MDN's page on the a element says current browsers already apply that to target="_blank", so the rel value mainly protects visitors on older ones. Add noreferrer too if the destination shouldn't learn which page sent the click.
The image-specific part is the warning. MDN recommends telling people when a link opens a new tab, and an image-only link has no visible text to carry that hint. So the alt text says it, as in the example. We prefer leaving internal image links in the same tab and saving target="_blank" for external sites the reader will want to come back from. Our HTML internal link guide explains how internal and external links differ.
Fixing the Border, the Gap Under the Image and the Focus Outline
Three cosmetic problems show up with linked images, and each has a one-line cause.
Blue border. Older browsers drew a border in the link colour around linked images, which is why old tutorials add border="0". That attribute is obsolete in HTML, and current browsers don't add the border. If a stylesheet adds one, remove it with CSS border: 0.
Gap under the image. An <img> is inline by default, so its bottom edge sits on the text baseline. The space below is room reserved for letter descenders, and it shows up as a few stray pixels inside the link. Make the image a block, or set vertical-align: bottom on it.
Missing focus outline. Some resets add outline: none to links, which hides where keyboard focus is. That fails WCAG 2.4.7 Focus Visible, a Level AA criterion. Restyle the outline instead of removing it.
This CSS handles all three:
.image-link {
display: inline-block;
}
.image-link img {
display: block;
border: 0;
max-width: 100%;
height: auto;
}
.image-link:focus-visible {
outline: 3px solid #1a5fb4;
outline-offset: 3px;
}
Add class="image-link" to the <a>. The outline now draws around the whole picture when someone tabs to it, and mouse clicks usually don't trigger it. max-width: 100% with height: auto lets the image shrink on narrow screens while keeping its proportions. For different files per screen size, the HTML image tag guide covers srcset and picture.
Hover Effects for a Clickable Image
A small hover change tells mouse users the picture is clickable. Keep it subtle, and give keyboard focus the same treatment:
.image-link img {
transition: opacity 0.2s, transform 0.2s;
}
.image-link:hover img,
.image-link:focus-visible img {
opacity: 0.85;
transform: scale(1.03);
}
@media (prefers-reduced-motion: reduce) {
.image-link img {
transition: none;
}
}
The image fades slightly and grows by 3 percent. The media query switches the animation off for people who've asked their system for reduced motion. If you want a linked image that looks like a button in a README instead, the Markdown button guide covers badge-style image links.
Linked Images in HTML Email
Email clients are stricter than browsers, so a linked image in a newsletter needs a slightly different shape:
<a href="https://example.com/sale">
<img src="https://example.com/email/sale-banner.png" alt="Spring sale: 20 percent off all plans" width="600" height="200" style="display:block; border:0;">
</a>
Use absolute https:// URLs for both the image and the link, because the email has no page address for relative paths to start from. Put the styles inline, since some clients strip or ignore <style> blocks. Keep the width and height attributes so the layout holds before images load.
The alt text matters even more here. Many email clients block remote images until the reader allows them, so the alt text is often the first thing a subscriber sees. Write it as a call to action. And don't depend on hover effects, because support for them in email is patchy.
Linking Parts of One Image with an Image Map
Sometimes one picture needs several destinations, such as rooms on a floor plan. An image map does that without cutting the image up:
<img src="/img/office-floor.png" alt="Office floor plan" width="600" height="400" usemap="#floor">
<map name="floor">
<area shape="rect" coords="0,0,300,200" href="/rooms/north" alt="North meeting room">
<area shape="circle" coords="450,300,60" href="/rooms/kitchen" alt="Kitchen">
</map>
The usemap value is a # followed by the map's name. Each <area> is one clickable region. rect takes the top-left and bottom-right corners, and circle takes a centre point and a radius. Every area with an href needs its own alt. Per MDN, an image with usemap can't sit inside an <a> or <button>.
The limitation is real: coords are fixed CSS pixel values. If your CSS scales the image down on a phone, the regions stay at their original positions and no longer line up. For responsive layouts, separate linked images or an inline SVG with links usually work better.
How Do I Use Images as Links in Markdown?
Markdown has a one-line version: [](link-url). The inner part is the image and the outer part is the link. The Markdown image guide covers it in full, and the Markdown links guide explains the link syntax around it.
Standard Markdown image syntax can't set width, height, target or a class. When you need any of those, write the HTML pattern straight into your Markdown. Most renderers pass raw HTML through, though hosted platforms often sanitise it and may drop some attributes. Try both versions here:
Both logos render as clickable images in the preview. The raw HTML one shows at the size you set, and the Markdown one shows at the file's own size. The Markdown to HTML converter runs in your browser and returns a full HTML document. In it, the Markdown line becomes an <a> wrapped around an <img>. Our editor has no image upload, so every image must be linked by URL.
The full hyperlink image HTML pattern is an <a> with an href, wrapped around an <img> that has src, a destination-naming alt, width and height. Add target and rel only for new tabs, keep a visible focus outline, and switch to inline styles for email. To test the markup next to its Markdown equivalent, paste both into the editor and compare the preview.