search

Image Link in HTML

Sep 04, 2024 pm 04:42 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

Image Link In HTML is found in almost all pages as they help us navigate from one page to another on a website. A popular combination is to use the HTML anchor tag with HTML’s img tag Image Link in HTML. With this combination, we can allow the movement of users from one page to another by clicking on an image. Before we dive further into this topic, let’s first understand the working and rendering of anchor and image elements individually and then combine them to achieve a linked image.

HTML Anchor Tag

The HTML Anchor tag is used to create HTML hyperlinks to other web pages or multimedia content hosted on the web. Let’s refer to the syntax below to understand how anchor tags work and their basic attributes

Click here!!

In the above example, the “href” attribute specifies the URL of the webpage to which we would like to redirect the user while click on the text “Click here!!”.

Let us see the complete code below :

Image Link in HTML

Output 

–>

With the above example, you will be able to make the following observations

  1. An unvisited link will appear underlined and in blue color. For, e.g. This is an unvisited Link
  2. A visited link will appear underlined and in purple color. For, e.g. This is an already visited Link
  3. An active link appears underlined and in red color. For, e.g. This is an active Link

HTML Image Tag

While browsing the internet, I am sure you must have come across several web pages which have various forms of multimedia included in them. Especially images are a popular form of multimedia that can be found in almost all interactive web pages and websites today. Let us understand the image tag and its implementation in HTML with the example below:

Syntax

<img src="/static/imghwm/default1.png" data-src="smiley.gif" class="lazy" alt="Smiley face"    style="max-width:90%"  style="max-width:90%">

Let us now understand how each of the attributes in the img tag work:

  1. src: The src attribute defines the image file path we are trying to load with this tag. It can be linked to an image hosted on the web with a format like example.com/images/dummy.png or an image file locally hosted on the same server as the web page.
  2. alt: The alt attribute defines the text and description of the image that we would like to display in case if the images fail to load due to network connectivity or any other issue.
  3. Width and height: The width and height of both attributes define the width and height of the image we’d like to display on the web page. Else the image would work with by default 100% height and width.

Now let’s see the complete HTML code required to load an image on a webpage. Save the following image by the name “sunset.png” in a folder called “image_test” in your local drive.

Image Link in HTML

Now in the same folder, let’s create an HTML file named sunset.html with the following HTML code :

Image Link in HTML

Now go to a browser on your machine and type in the path of the .html file. My files are stored in a D drive, so the path for me would be

D:/image_test/sunset.html

And now we can see that the rendered HTML page has loaded the sunset image on our browser. With the help of CSS and

tag, we can also display text as per our requirement around the image. Both the anchor and img tags are compatible with all browsers like Google Chrome, Safari, Microsoft Edge, Firefox and Internet Explorer.

Linked Images in HTML

Now that we have understood with examples how anchor tag and image tag work individually, let us now understand how we can combine the two functionalities to achieve a scenario where we would like the users to be redirected to a new webpage with the click of an image. To make an image clickable and redirect the user to another webpage, we simply need to nest the image in an anchor tag. In the below example, we will try to enlist the top 3 web search engines used across the globe. In our list, we will show the logos of the 3 search engines, and by clicking on any of the logos, the user will be redirected to the respective search engine page. Let us create a folder named “redirection test”, and in the same folder, let’s save the below images

1. Google

Image Link in HTML

2. Yahoo

Image Link in HTML

3. Bing

Image Link in HTML

Now we will create a .html by the name imageredirection.html in the same file. The imageredirection.html will contain the following code.

Image Link in HTML

Now we need to access the HTML page from the browser, for which I will type my local path “D:/redirectiontest/ imageredirection.html”. the browser will then render the HTML file to generate the following result:

–>

The users will be able to navigate to the respective search engine by clicking their logo. From the above example, we can observe that HTML is a simple and flexible language that allows us to combine multiple tags together and achieve a complex functionality like this. The combination of using img and anchor tag is a popular combination.With additional HTML coding we can also add different HTML elements like displaying linked images in an ordered or unordered list using

    or
    . The extreme flexibility and simplicity that HTML provides with each version released help UI and UX designers design interactive and intuitive web pages that we see while browsing the internet for day to day activities.

    Recommended Article

    This has been a guide to Image Link in HTML. Here we discuss the Different Types of HTML Tags Along with Syntax. You can also go through our other suggested articles to learn more –
  1. HTML Attributes
  2. HTML Format Tags
  3. HTML Image Tags
  4. HTML Frames

The above is the detailed content of Image Link in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

How to implement multi-project carousel in Bootstrap 4?How to implement multi-project carousel in Bootstrap 4?Apr 30, 2025 pm 03:24 PM

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How does deepseek official website achieve the effect of penetrating mouse scroll event?How does deepseek official website achieve the effect of penetrating mouse scroll event?Apr 30, 2025 pm 03:21 PM

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

How to modify the playback control style of HTML videoHow to modify the playback control style of HTML videoApr 30, 2025 pm 03:18 PM

The default playback control style of HTML video cannot be modified directly through CSS. 1. Create custom controls using JavaScript. 2. Beautify these controls through CSS. 3. Consider compatibility, user experience and performance, using libraries such as Video.js or Plyr can simplify the process.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.