Lesson 4 of 23

In progress

Course progress

HTML and CSS

Links that go where they say

Connect pages with relative and absolute links, link within a page, and write link text that makes sense out of context.

The link is what makes a collection of pages a web. It is also the element most often written carelessly: "click here" tells a screen reader user nothing, and a wrong path produces the 404 you spend an hour debugging.

What you will learn

  • Write links with href and understand what the browser does with it.
  • Tell relative, root-relative and absolute paths apart.
  • Link within a page and open new tabs responsibly.

The anchor element

HTML
Editable. Runs in your browser.





Press Run to see the output.

href is the destination. The text between the tags is the link, and it is what a person reads and what a screen reader announces. Vague text such as "here" or "read more" is a problem because the destination is invisible when links are read out of context.

Write the link text so the sentence works without the surrounding paragraph: "the MDN guide to Flexbox" beats "this guide".

Three kinds of path

A relative path is resolved from the current file’s location. about.html means a file beside this one. ../images/logo.png means up one folder, then into images.

A root-relative path starts with a slash and is resolved from the site root: /tutorials/python/. It works on the server and in local development if the server is rooted at the project folder. It breaks when you open the file directly with file://, because the root is then your hard drive.

An absolute URL includes the protocol and host: https://example.com/about. Use it for other sites. For your own pages, relative paths survive domain changes and work on staging.

HTML
Editable. Runs in your browser.





Press Run to see the output.

Changing the site from http://localhost:8000 to a real domain breaks nothing in the first link and everything in a hard-coded localhost absolute URL. That is the practical argument for relative paths.

An id on an element creates a target. href="#setup" scrolls to it.

HTML
Editable. Runs in your browser.





Press Run to see the output.

The fragment is handled by the browser, not the server. Ids must be unique on the page; duplicates make the browser pick one and confuse everything else. A "back to top" link usually points at #top with an id on the header or uses href="#", though the latter changes the URL and can behave inconsistently.

New tabs need a reason

target="_blank" opens a new tab. It is useful for a reference the reader will return from, and annoying when every link does it.

If you use it, add rel="noopener" (modern browsers imply it, but being explicit is harmless) and consider noreferrer. Also tell the reader the link opens a new tab, either in the text or with a visually hidden note; unexpected context changes are an accessibility problem.

HTML
Editable. Runs in your browser.





Press Run to see the output.

Email, phone and downloads

mailto: opens the mail client, tel: dials on a phone, and the download attribute suggests saving instead of navigating.

HTML
Editable. Runs in your browser.





Press Run to see the output.

A mailto: link is not a contact form. It depends on the visitor having a mail client configured, and it exposes the address to scrapers. A form on the server is the reliable option when you need to receive messages.

Writing <a href="page.html"> for a page in a subfolder produces a 404 that looks like the file vanished. Relative paths are resolved from the document, not the site root. Check the Network panel: the request URL tells you exactly where the browser looked.

Write a navigation list with three links: one to index.html, one to about.html in the same folder, and one to an external documentation site that opens in a new tab with the reader warned. Then add a "skip to content" link pointing at a main element with an id.

Show solution
HTML
Editable. Runs in your browser.





Press Run to see the output.

The skip link comes first in the source so it is the first thing a keyboard user reaches. The nav has a label because a page can have more than one navigation region.

Recap

  • href sets the destination and the link text describes it; avoid "click here".
  • Relative paths resolve from the document, root-relative from the site root, absolute from the protocol and host.
  • #id links within a page, and target="_blank" needs a warning and rel="noopener".

Next, you will add images with alternative text that actually helps.

Should links be underlined?
In body text, yes, or otherwise clearly distinguishable without relying on colour alone. Removing the underline is a design choice, but keep a visible difference on hover and focus.
Can I link to a PDF?
Yes, but say so in the link text and mention the size when it is large. A visitor on a phone deserves to know a link opens a download rather than a page.

Full syllabus

Progress is saved in this browser only. No account, no email.

Admin

About the author

Admin

Instructor and technical writer at tutorials.in

Writes beginner lessons for tutorials.in. Each lesson is checked against the language or tool documentation, and examples are run before publishing.

Reviewed by the editorial team before publishing. Last updated November 16, 2026.