Lesson 3: Links & Images
Lesson 03: Links & Images
Learn how to connect webpages and display images using HTML.
HTML COURSE · LESSON 03
01. What are HTML links?
Links allow visitors to move from one webpage to another. They can also lead to external websites, files, or specific sections of a page.
The HTML element for a link is called an anchor element: <a>.
<a href="https://example.com">
Visit Example
</a>
Let's break it down:
<a>creates the link.hreftells the browser where the link goes.Visit Exampleis the clickable text.</a>closes the element.
02. Opening links in a new tab
You can use the target attribute to control where a link opens.
<a href="https://example.com"
target="_blank"
rel="noopener">
Open in a new tab
</a>
target="_blank" opens the link in a new tab or window.
rel="noopener" adds protection when opening an external page in a new tab.
03. Linking to another page on your website
You can link to another page on the same website using a relative URL.
<a href="/about/">
About Us
</a>
This example sends visitors to the About page on the same website.
04. Adding images
Images make webpages more interesting and help communicate information.
HTML uses the <img> element to display an image.
<img
src="image.jpg"
alt="A description of the image"
width="300"
>
Here's what each attribute does:
srcspecifies the image location.altdescribes the image for screen readers and when the image cannot load.widthsets the image width.
05. Making an image clickable
You can put an image inside a link. That makes the image clickable.
<a href="https://example.com">
<img
src="image.jpg"
alt="Visit Example"
>
</a>
Now clicking the image takes the visitor to the linked website.
06. Try It Yourself
Which HTML attribute tells an image where its file is located?