Skip to Content
👆 We offer 1-on-1 classes as well check now
Web BasicsHTML ContentLinks and Images

Links and Images

Links (or hyperlinks) and images are fundamental elements that make the web interactive and visually appealing. They allow users to navigate between pages and see the content you want to display. This guide will introduce you to the basic syntax for using links and images in your HTML.

A link, also known as a hyperlink, is a clickable element that takes you to another web page, a specific section within the same page, or even allows you to download a file. Links are crucial for website navigation and connecting different parts of the internet. They’re created using the <a> tag (anchor tag).

Here’s how to create a simple link:

<a href="https://www.example.com">Visit Example Website</a>

Explanation:

  • <a href="...">: This is the anchor tag. The href attribute specifies the URL (web address) of the page you want to link to.
  • https://www.example.com: This is the URL the link points to. Replace this with the address you want to link to.
  • Visit Example Website: This is the text that the user will see and click on. It’s the “clickable” part of the link.

What is an Image?

Images are crucial for visual communication on the web. They make your web pages more engaging and informative. You include images in your HTML using the <img> tag.

Basic Example: Adding an Image

Here’s how to add an image to your webpage:

<img src="image.jpg" alt="Description of the image">

Explanation:

  • <img src="..." alt="...">: This is the image tag. It doesn’t have a closing tag.
  • src="image.jpg": The src attribute specifies the path (location) of the image file. Make sure the image file (image.jpg in this example) is in the same directory as your HTML file, or specify the correct path (e.g., images/image.jpg if the image is in an “images” folder). You can also use a URL like src="https://www.example.com/image.jpg"
  • alt="Description of the image": The alt attribute provides a text description of the image. This is important for accessibility (for users with visual impairments) and SEO (search engine optimization). If the image cannot load, the alt text will be displayed instead.

You can also use images as links. This is a common way to create image-based navigation or clickable banners:

<a href="https://www.example.com"> <img src="logo.png" alt="Example Logo"> </a>

Explanation:

In this example, the <img> tag is placed inside the <a> tag. When the user clicks the image (logo.png), they will be taken to https://www.example.com.

Key Takeaways

  • Use the <a> tag with the href attribute to create links. The href attribute specifies the destination URL.
  • Use the <img> tag with the src attribute to display images. The src attribute specifies the image’s file path.
  • Always include the alt attribute in your <img> tags for accessibility and SEO.
  • You can nest <img> tags inside <a> tags to make images clickable links.
Last updated on