Links
The anchor tag <a> creates a hyperlink. The href attribute holds the destination.
<a href="https://example.com">Visit Example</a>
<a href="https://example.com" target="_blank" rel="noopener">Open in a new tab</a>
<a href="mailto:hello@example.com">Send an email</a>
<a href="#section2">Jump to section 2</a>target="_blank"opens a new tab. Addrel="noopener"for safety.mailto:opens the visitor's email app.#idjumps to an element with that id on the same page.
Absolute and relative paths
- Absolute: the full address, like
https://example.com/page.html. - Relative: a path from the current file, like
about.htmlorimages/photo.jpg.
Images
<img src="images/photo.jpg" alt="Students studying in a library" width="600" height="400">srcis the image location.altdescribes the image for screen readers and shows if the image fails to load. Never skip it.widthandheighthelp the browser reserve space so the page does not jump while loading.
Image as a link
<a href="gallery.html"><img src="thumb.jpg" alt="Open the gallery"></a>Good practice
- Use descriptive link text such as Read the HTML guide instead of click here.
- Compress images before uploading. Large images slow the page.
- Use modern formats such as WebP when you can.
Practice
Create a page with a link to a website you like, a link to your own second page and one image with proper alt text.
Practice tasks
Reading is not enough. Try these without copying code, then compare with the lesson.
- Add three links: to an external site, to another page of yours and to an email address.
- Insert an image with meaningful alt text and a width.
- Make the image a link and check it by keyboard.
Common mistakes
- Missing alt text, which makes images unusable for screen reader users.
- Using a wrong file path so the image does not load.
Quick check
What is the difference between absolute and relative URLs?
An absolute URL contains the full address; a relative one is based on the current file location.
What does target="_blank" need for safety?
rel="noopener" so the new page cannot access the opener.