Links and paths
The href of a link says where it goes. It can be a full address, a path, or a special link that starts an e-mail or a phone call.
Step by step
- A full address like
https://example.org/can go to another website. - A relative path like
hybris.htmllooks for a file next to the current page. blog/goes into a folder,./means this folder, and../goes up one folder (often needed in subfolders).- A path that starts with
/, like/img/logo.png, starts from the root of the site, whatever folder the page is in. mailto:[email protected]starts a new e-mail. Withoutmailto:, the browser treats the address as a page path.tel:+12025550123asks a phone to call. The prefix istel:, notphone:; write+, the country code, no spaces.<base href>in<head>moves where relative paths start. End it with/for a folder, or its last part is replaced.- A path that starts with
/still begins at the site root, so the folder in<base>does not apply to it.
The card, bug marked
1<h2>Bands & Releases</h2>
2<ul>
3 <li><strong>Band A</strong>:
4 <a href="nemesis.html">Nemesis</a>,
5 <a href="hybris.htm">Hybris</a>
6 </li>
7 <li><strong>Band B</strong>:
8 <a href="faceless.html">Faceless</a>
9 </li>
10</ul>
This is how it's right
<a href="hybris.html">Hybris</a>
<a href="blog/">Blog</a>
<a href="../">Home</a>
<a href="https://example.org/">Other site</a>
<img src="/img/band-logo.png" alt="Band logo">
<a href="tel:+12025550123">Book a guitar lesson</a>
Exercises for this topic
- Find the bug.
- This page is on example.com. Which link leads to another website?
- Find the bug.
- Find the bug.
- You tap the link on a phone. What does the link ask the phone to do?
- Find the bug.
- Find the bug.
- You tap the album cover photo. What happens?
- Which words are clickable as a link?
- Find the bug.
- Find the bug.
- This page is at example.com/blog/tuning.html. Which address opens when you tap "Home"?
- Find the bug.
- This page is at https://example.com/blog/. Which address opens when you tap "Contact"?
Key rule
A path without a leading / starts from the current page's folder (or from <base>); a leading / starts from the site root.
Where you'll meet this
Every menu and every CSS or image link uses paths. One typo in a file name leads to a "not found" page. Contact pages use mailto: and tel: links.