HTML – IMAGE LINKS

Example


Example 6: Using a Larger Image for Better Aesthetics
Example 8: Image Links as Buttons
Example 9: Responsive Image Links

<a href="URL">
<img src="IMAGE_URL" alt="DESCRIPTION">
</a>
Example 1: Clickable Image Link
<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Example Website">
</a>
- href: The URL you want to navigate to when the image is clicked.
- src: The source of the image.
- alt: Describes the image for accessibility and displays text if the image fails to load.
This will produce the following result:

Example 2: Image Links with Styling.
You can style your image links using CSS for size, border, or hover effects:

Example 3: Open Link in a New
<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Hover Effect" style="border: 2px solid black; border-radius: 10px;">
</a>
This will produce the following result:

Tab
To open the link in a new browser tab:

<a href="https://www.mahekinstituterewa.com" target="_blank">
<img src="logo.png" alt="New Tab Link">
</a>
This will produce the following result:

- target="_blank": Opens the link in a new tab.
Example 4: Image Link with Tooltip
Add a tooltip to provide additional information:
<a href="https://www.mahekinstituterewa.com" title="Visit Example Website">
<img src="logo.png" alt="Example with Tooltip">
</a>
This will produce the following result:

Example 5: Image Links with Text Underneath
Combine text with your image link for better usability or context.

<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Example Link">
<br>
Visit Example Website
</a>
This will produce the following result:

For websites, you might want to use a larger and properly styled image:

<a href="https://example.com">
<img src="https://via.placeholder.com/500x300" alt="Larger Example Image" style="max-width: 100%; height: auto;">
</a>
This will produce the following result:

- max-width: 100%: Ensures the image scales properly on different screen sizes.
- height: auto: Maintains the aspect ratio of the image.
Example 7: Adding Multiple Image Links
You can create a gallery or navigation bar using multiple image links.

<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Link 1">
Link 1
</a>
<a href="https://www.mahekinstituterewa.com/p/html-image-links.html">
<img src="logo.png" alt="Link 2">
Link 2
</a>
<a href="https://www.mahekinstituterewa.com/2024/12/html-text-links-tutorial.html">
<img src="logo.png" alt="Link 3">
Link 3
</a>
This will produce the following result:

Style an image link to look like a button:

<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Button Image" style="padding: 10px; background-color: #007BFF; border-radius: 5px; box-shadow: 2px 2px 5px gray;">
</a>
This will produce the following result:

Make image links responsive for mobile devices using CSS.
<style>
img {
width: 100%; /* Full width for smaller screens */
max-width: 300px; /* Limit the size on larger screens */
height: auto; /* Maintain aspect ratio */
}
<a href="https://www.mahekinstituterewa.com">
<img src="logo.png" alt="Responsive Image">
</a>
This will produce the following result:

Make the image change appearance when hovered over.
<style>
a img {
transition: transform 0.3s ease, opacity 0.3s ease;
}
a img:hover{
transform: scale(1.1); /* Slight zoom effect */
opacity: 0.8; /* Slight transparency */
}
</style>
<a href="https://example.com">
<img src="https://via.placeholder.com/150" alt="Hover Effect Example">
</a>
This will produce the following result:
You can also link an image to an email address:

<a href="mailto:info@mahekinstituterewa.com">
<img src="maillogo.png" alt="Hover Effect Example">
</a>
This will produce the following result:

You can use image links for navigation within the same page using id attributes.
<a href="#section1">
<img src="https://via.placeholder.com/150" alt="Go to Section 1">
</a>
<h2 id="section1">Section 1</h2> <p>This is the content of Section 1.</p>
This will produce the following result:

Frequently Asked Questions (FAQ)
Q 1. What is an image link?
Answer: An image link is a clickable image that navigates to another webpage, file, email, or any other resource when clicked. This is created by nesting an <img> tag inside an <a> tag.
Answer: You can wrap the <img> tag inside an <a> tag. For example:
<a href="https://example.com">
<img src="https://via.placeholder.com/200" alt="Example Link">
</a>
Q 3. Can I link to a specific section of the same page using an image?
Answer: Yes, use an id attribute on the target element and a # followed by the ID in the link:
<a href="#section1">
<img src="https://via.placeholder.com/200" alt="Go to Section 1">
</a>
<h2 id="section1">Section 1</h2>
Q 4. How do I make the link open in a new tab?
Answer: Add the target="_blank" attribute to the <a> tag:
<a href="https://example.com" target="_blank">
<img src="https://via.placeholder.com/200" alt="Open in New Tab">
</a>
Q 5. How do I make an image link to a downloadable file?
Answer: Use the download attribute in the <a> tag:
<a href="example-file.pdf" download>
<img src="https://via.placeholder.com/200" alt="Download File">
</a>
Q 6. Can I link an image to an email address?
Answer: Yes, use the mailto: scheme:
<a href="mailto:example@example.com">
<img src="https://via.placeholder.com/200" alt="Email Us">
</a>
Q 7. How can I make an image link to a phone number?
Answer: Use the tel: scheme for clickable phone numbers:
<a href="tel:+1234567890">
<img src="https://via.placeholder.com/200" alt="Call Us">
</a>
Q 8. Can I add a tooltip to an image link?
Answer: Yes, use the title attribute:
<a href="https://example.com" title="Click to visit Example.com">
<img src="https://via.placeholder.com/200" alt="Tooltip Example">
</a>
Q 9. Is it necessary to include the alt attribute in image links?
Answer: Yes, the alt attribute is important for accessibility and for providing a fallback description if the image fails to load. Always include meaningful alt text:
<a href="https://example.com">
<img src="https://via.placeholder.com/200" alt="Visit Example.com">
</a>
Q 10. Can I create multiple image links on one page?
Answer: Yes, you can include as many image links as you like:
<a href="https://example1.com">
<img src="https://via.placeholder.com/100" alt="Link to
Example 1">
</a>
<a href="https://example2.com">
<img src="https://via.placeholder.com/100" alt="Link to Example 2">
</a>
Q 11. Can I make an image link responsive without CSS?
Answer: Without CSS, you can set the image's width as a percentage in the width attribute:
<a href="https://example.com">
<img src="https://via.placeholder.com/200" alt="Responsive Image" width="100%">
</a>
Q 12. What happens if the image doesn’t load?
Answer: If the image doesn’t load, the text provided in the alt attribute will be displayed. Example:
<a href="https://example.com">
<img src="nonexistent-image.jpg" alt="Image failed to load">
</a>
Q 13. Can I link an image to a video or social media page?
Answer: Yes! Link to any URL you want:
Video:
<a href="https://youtube.com">
<img src="https://via.placeholder.com/200" alt="Watch on YouTube">
</a>
Social Media:
<a href="https://facebook.com">
<img src="https://via.placeholder.com/200" alt="Visit Facebook">
</a>