How to add a link to an image in HTML (2024)

Table of Contents
Syntax Example Explanation FAQs

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

We can link one webpage to another by using an image as a link. This link is called a hyperlink.

We use the <img> tag to display an image. The <a> tag is used to create a hyperlink. Placing an <img> tag inside an <a> tag displays a clickable image that leads to another page.

The <a> tag has an attribute, href. The href attribute's value specifies the location of the webpage we want to link.

Syntax

The <a> tag encapsulates the <img> tag. This encapsulation applies the hyperlink to the image.

Example

Add a hyperlink to the Educative home page on an image of the Educative logo

Explanation

  • Line 5: We create a hyperlink using the <a> tag. We set the destination page to the Educative home page using the href attribute. The target attribute tells the browser how to open the webpage. We use the "_blank" value to open the page in a new window or tab.
  • Line 6: We create an image using the <img> tag. Using the src attribute, we specify the location of the image we want to display. In this case, we give the URL for the Educative logo.

Note: Click here to explore the other options of the target attribute.

Instead of mentioning a URL in the src attribute of the <img>, we may also provide a file path. We do this when the image we want to display is saved on our computer. In other terms, the image is locally stored. We can see an example below:

Press

+

to interact

<img src="./myFolder/image.png">

RELATED TAGS

html

image

hyperlink

image hyperlink

CONTRIBUTOR

How to add a link to an image in HTML (1)Rana Abdul Muneem

Copyright ©2024 Educative, Inc. All rights reserved

How to add a link to an image in HTML (2024)

FAQs

How to put a link on an image in HTML? ›

This link is called a hyperlink. We use the <img> tag to display an image. The <a> tag is used to create a hyperlink. Placing an <img> tag inside an <a> tag displays a clickable image that leads to another page.

How do I pass an image to a URL in HTML? ›

There are two ways to specify the URL in the src attribute: 1. Absolute URL - Links to an external image that is hosted on another website. Example: src="https://www.w3schools.com/images/img_girl.jpg".

How do I add a link in HTML? ›

A basic link is created by wrapping the text or other content inside an <a> element and using the href attribute, also known as a Hypertext Reference, or target, that contains the web address.

How do I link an image icon in HTML? ›

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)

How to make a link clickable? ›

Create a hyperlink to a location on the web

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.

How do I embed an image in a URL? ›

Copy and paste your image URL into an IMG tag, add a SRC to it. Identify first where you'd like to place your image within the HTML and insert the image tag, <img>. Then take your uploaded image, copy the URL and place it within your img parameters prefaced by a src.

What is the URL image link? ›

An image URL is a web address that can be used to find an image online. They look and act just like normal URLs, but instead of telling you what page to load, they tell you what image to load. These URLs are then inserted into a webpage, which can interpret the URL and render it as the actual image instead of a link.

How do I hyperlink an image in HTML? ›

Put the anchor tag <a href=””> before the image url, and </a> after. Paste the destination URL you want to add within the quotation marks for <a href=””>. Make sure you put “http://” before the link. Now enjoy the hyperlink in your customized image if you have followed these steps properly.

How to make an image clickable in HTML? ›

How To Create A Clickable Image 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 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 copy the URL of an image? ›

Right-click on the image and select Copy Image Link from the menu that opens. Paste the address into a new email, text editor, or new browser window. Another option in most browsers is to open the image in a new tab or window, and then copy the address from the URL bar of the browser.

How do I import an image URL into HTML? ›

In order to put a simple image on a web page, we use the <img> element. This is a void element (meaning, it cannot have any child content and cannot have an end tag) that requires two attributes to be useful: src and alt . The src attribute contains a URL pointing to the image you want to embed in the page.

How to do nesting in HTML? ›

HTML elements may contain other elements. This is called nesting, and to do it properly, the entire element (including its markup) must be within the start and end tags of the containing element (the parent). Proper nesting is one of the criteria of a well-formed document (a requirement for XHTML).

Top Articles
Latest Posts
Article information

Author: Arline Emard IV

Last Updated:

Views: 6295

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.