Linking Image in HTML: How to create links from images (2024)

We are going to take a beginner friendly look at how to create image links on your website.

We will look at which HTML tags you need to use in the code.

If you have never done this before, don't worry! I will guide you through the whole process.

By the end of this article, you will be creating image links all over your web page and the Internet.

We are also going to look at some more advanced techniques towards the end of the article if you are feeling brave.

Grab a coffee, let's dive in!

How do you Create a Hyperlink?

To get links on your home page you need to create a hyperlink. To do this in HTML you need to use an <a> tag. Each <a> tag has two parts the opening and closing tag.

Here is an example:

<a href="..."> ...</a>

In the above, you can see that the open tag:

<a href="...">

Creates the start of the hyperlink. Then we close the tag with:

</a>

Any text that we write between the open and close tag is your link text. For Example:

<a href="..."> My Great Link</a>

To turn this into a link we need to add a URL. To do this we add the URL to the href attribute. The URL can point to anywhere on the internet. For this example we are going to use the PageDart homepage:

<a href="https://pagedart.com"> My Great Link</a>

Make sure to include the full URL with HTTPS at the front.

That is all there is to create a text-only link in HTML. Next, let's look at how we can add an image to a web page using HTML.

How do you Create an image in HTML?

To add an image to your web page use an img tag.

This tag is a bit different from an a tag in that it does not have an opening and closing tag.

To create an img tag you need to give the tag a source file. Use the src attribute to do this:

<img src="/favicon-32x32.png">

This will add an image to the screen like this:

Now we have an image we need to turn it into a link. To do that we need to add a <img> tag inside the <a> tags creating a linking image in HTML.

Let's look at an example next.

Image as a link

To turn an image into a link you need to add the <img> tag inside the <a> tag. So taking our earlier example the source code would look like this:

<a href="https://pagedart.com"> <img src="/favicon-32x32.png"></a>

Which would produce this HTML:

By adding the <img> tag inside an <a> tag the browser can see that the image should be clickable. You have turned the image into a link!

If you are using WordPress then you can add this HTML code to your page using the text view in the page editor.

You can also add text and images inside the link, let's look at this.

Image and Text as a Link

The example above showed how to add only an image as the link.

What if we wanted to add both an image and text to a link.

Well, in this case, we need to make sure that we add the text before we close the <a> tag:

<a href="https://pagedart.com"> <img src="/favicon-32x32.png"> PageDart Home </a>

In the above, we have added “PageDart Home” inside the <a> tag along with the <img> tag. When shown in a web browser on the page it will look like this:

There is one more attribute on the <img> tag that we have not discussed and you should be using.

It is the alt attribute.

Image Links and the Alt Attribute

Images on the internet should have an alt attribute. This is a text description of the image.

Screen readers use the alt text to help visually impaired users. The screen readers will read out the text description when it finds an image.

To do this we add an alt attribute to the img tag like this:

<a href="https://pagedart.com"> <img alt="PageDart.com" src="/favicon-32x32.png"></a>

Now when the screen reader reads this image it will say “PageDart.com” out loud.

It is important to follow best practices when writing image alt text.

Make sure you think about the person who is using the screen reader. Write your alt text description for them and describe the image as best you can.

This is all you need to create linking images in HTML. Yet, there are a few more advanced techniques that you can use. If you are feeling brave we will look at these next.

Advanced Technique: Image as a Link using CSS

A more advanced technique is to use CSS. CSS stands for Cascading Style Sheet and it allows you to change how a HTML page looks.

With CSS you can set a background image on an element such as our <a> tag.

Here we would have HTML that looks like this:

<style> a { background-image: url("/favicon-32x32.png"); display: block; height:32px; width:32px; }</style><a href="https://pagedart.com"></a>

So this time there is nothing inside the <a> tag but the image is set using the CSS style. This would show the following in the browser:

We can use a similar technique with a <button> tag.

Advanced Technique: Using a Button

In this example, we are going to use the <button> tag instead of the <a> tag.

We can create the same output as the example above using this HTML:

<style> .link { background-image: url("/favicon-32x32.png"); border: 0; height:32px; width:32px; }</style><script> function goHome() { return window.open("https://pagedart.com", "_blank") }</script><input type="button" class="link" onclick="goHome()"/>

Which creates this output:

Here we are using JavaScript to open a new browser tab. Sending the user to the PageDart home page.

I have no idea why you would ever do this! But, I wanted to show you what is possible and how flexible HTML, CSS and JavaScript can be.

The last example I am going to show is using an image map.

Advanced Technique: Image Map

Image maps are single images with clickable areas. They have lost popularity over the years but they are still part of the HTML5 specification. This means that browsers such as Internet Explorer, Chrome and Safari will support them.

Charts are good examples of Image Maps such as organizational charts, like this:

Then to make each pink area a clickable link we would create a map like this:

<img src="org.png" alt="Staff Organisation Chart" usemap="#Map"><map name="Map" id="Map"><areashape="rect"coords="176,14,323,58"href="…"alt="Chairman"> <area shape="rect" coords="81,75,226,114" href="…" alt="Secretary" > <area shape="rect" coords="6,138,155,182" href="…" alt="Marketing Director" > <area shape="rect" coords="175,138,323,182" href="…" alt="Sales Director" > <area shape="rect" coords="345,136,496,186" href="…" alt="Finance Director" ></map>

We have added the attribute usemap to the img tag.

Then within the map tag we have an area tag. Each of these areas creates a clickable area that acts as a button.

Using a Linking Image in HTML

We have looked at five different ways to add an image as a link on your web page:

  1. An image as a link
  2. Image and text as a link
  3. Using CSS to set an image as a link
  4. Using a button as a link
  5. Using image maps

All these can turn images into links. You should now have the confidence to try this yourself.

We have also looked at accessibility and how to set Alt text to help the visually impaired.

Linking Image in HTML: How to create links from images (2024)

FAQs

Linking Image in HTML: How to create links from images? ›

Image as a link

How do I turn an image into a link in HTML? ›

The <img> and the <a> tags together is the most common way of adding a clickable image link in HTML. In a webpage, after adding an image using the <img> tag, make it clickable by adding a <a> tag along with it.

How can I make a clickable link on pictures images? ›

To make a picture a clickable link, use the HTML code: <a href="https://www.wikihow.com"><img src="full-path-to-image. jpg"></a>. Web editors like WordPress and Wix as well as email programs and image platforms like Gmail and Canva have built-in functionality to add a link when you select your image.

How do you generate a URL for an image in HTML? ›

Right-click on the image you want to get the URL for. Click on "Inspect" to open the Developer Tools window. In the new window that opens, look for the HTML code that represents the image. You should see the URL of the image in the code, likely in an "img src" tag.

How do you reference an image link in HTML? ›

Tip: To link an image to another document, simply nest the <img> tag inside an <a> tag (see example below).

How do I get a link from an image? ›

Get an image URL
  1. On your Android phone or tablet, open the Google app , Chrome app. , or Firefox.
  2. Go to images.google.com.
  3. Search for the image.
  4. In Images results, tap the image to get a larger version.
  5. Copy the image URL based on your browser: Google app: At the top right of the image, tap More. Share. Copy .

How do I link a local image in HTML? ›

In order to insert an image in HTML from a folder you will need to use the <img> tag. The src attribute is used to specify the location of the image. You can link to an image using either an absolute or relative file path.

How do I create a link from photos? ›

  1. On your mobile device, open the Google Photos app .
  2. Sign in to your Google Account.
  3. Select a photo, album, or video.
  4. Tap Share .
  5. Under “Share to apps,” select another app to share to. Swipe left to find more apps.
  6. To create and share a link, tap Create link.

How do I turn a jpg into a link? ›

Re: Create a clickable link using a . jpg image. @Steve_Burnes Insert the image into the document and then with it selected, go to the Insert tab of the ribbon and click on the Linl dropdown and then on Insert Link and then insert the URL in the control highlighted in the following screen shot and then click on OK.

How to generate an image link? ›

Get an image URL
  1. On your computer, go to images.google.com.
  2. Search for the image.
  3. In Images results, click the image.
  4. In the right panel, click More Share .
  5. Under “Click to copy link,” click the URL.

How do I copy an image as a link in HTML? ›

In HTML, we can use the <img> element to add images on the page. In this example, we are adding an image of five cats. If we wanted to make that image a clickable link, then we can place it inside a set of anchor tags. We can also add the target="_blank" attribute to have that link open up in a new tab.

How do I pass an image to a URL? ›

Example: src="img_girl. jpg". If the URL begins with a slash, it will be relative to the domain. Example: src="/images/img_girl.

How do I add a link in HTML? ›

Use this code to add a Link to a page:
  1. <a href=“http://Internet URL goes here.”> ...
  2. Code example: <a href=http://www.example.com>Example</a>
  3. <img src=“image name goes here” align=“Use left, right or center”>
  4. Code example: <img src= “house.jpg” align=“center”>
  5. <a href=“mailto:someone@home.net”>E-mail Us</a>

What is image linking in HTML? ›

4.8. note: An image link in HTML is an image that can act like a hyperlink and can point us to another location. Suppose we are reading an article on the internet that has it. Suppose we click on an image and then redirects us to a different page. In this case, the image is acting as an image link in an HTML document.

How can you link an image as a hyperlink to another document? ›

Select the text or picture that you want to display as a hyperlink. Link. You can also right-click the text or picture and click Link on the shortcut menu. In the Insert Hyperlink box, type or paste your link in the Address box.

What is the correct HTML for creating a hyperlink? ›

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a herf=" ">.

How do images serve as hyperlink in HTML? ›

The HTML <a> type attribute is used to create a hyperlink to web pages, files, and locations on the same page. We can make elements like images into links by nesting them within an <a> element. It defines a hyperlink that is used to link from one page to another.

How to create a link in HTML? ›

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.

How to make an icon a link in HTML? ›

Take a regular <a> element, add .icon-link , and insert an icon on either the left or right of your link text. The icon is automatically sized, placed, and colored.

Top Articles
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 6102

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.