Plate 1.3 · Phase 1 — Framing · 20 minutes
Links: the thing that makes it a web
A page on its own is a document. Pages that point at each other are a web — that's where the name comes from. This module is about one element, <a>, which is arguably the single most important invention in the history of the internet.
Warm-up · from Module 1.2An <h2> looks too big for your design. What do you do?
Keep the <h2> — it's the right rank in the outline — and change its size with CSS in Phase 2. Headings are ranks, not font sizes.
Why this one element matters so much
In 1989, at CERN outside Geneva, Tim Berners-Lee had a practical problem: thousands of physicists writing documents on different computers, and no way to get from one to another. His proposal was simple. Let any document point at any other document, anywhere, with one click. He called the pointers hypertext links, and the network of documents they created a World Wide Web.
Every other invention in this manual — CSS, JavaScript, the whole of Phase 7 — was built on top of that one idea. You are about to learn the element that implements it.
The anatomy of a link
<a href="https://www.nps.gov/yell/"> Yellowstone National Park </a>
A signpost on a trail
- The post
- Planted in the ground, pointing one specific way. You don't read it — it just determines where you end up.
- The words painted on the sign
- "Old Faithful — 2 miles." What hikers actually read, and how they decide whether to take that path.
A link
href— where it goes- Short for hypertext reference. The destination. Visitors never see it unless they hover.
- The link text — what people read
- Everything between the tags. What people click, what screen readers announce, and what Google uses to understand the page on the other end.
The a stands for anchor — a historical name nobody uses in conversation. Everyone just says "link".
Five places a link can point
The href can hold five quite different kinds of destination. Pick one below, change the fields, and the correct markup writes itself — along with what happens when someone clicks it, and anything you've done that a professional would flag.
| Kind of link | Code | What happens |
|---|---|---|
| Another site | <a href="https://www.nps.gov/yell/"> | Leaves your site. |
| Your own page | <a href="about.html">About me</a> | Stays on your site. The path is found relative to the current page, as in Module 0.3. |
| Same page | <a href="#opening-hours">Opening hours</a> | Scrolls to the element with id="opening-hours". Nothing is requested from the server. |
<a href="mailto:hello@cedarandpine.com | Opens the email app with the subject filled in. Spaces become %20. | |
| Phone | <a href="tel:+15035550142"> | Dials with one tap on a phone. Spaces and punctuation are left out of the href. |
Notice that one tag does all five jobs. Only the start of the href changes. Add target="_blank" only when leaving would lose the visitor's work, and say so in the link text.
Two of those are worth underlining. Another site must start with https:// — leave it off and the browser assumes you mean a file inside your own project, exactly the relative-path rule from Module 0.3. And Phone links are one of the most valuable lines you can put on a small business's site: on a phone, a tap dials the number. Every restaurant, plumber and dentist should have one.
Same-page links: a table of contents in two halves
A jump link needs two things that match: an id on the place you're jumping to, and a link whose href is that id with a # in front. You've seen the # before — it's the fragment from the URL anatomy in Module 0.1, the one part of an address that never leaves your browser.
<!-- the link, near the top --> <a href="#hours">Opening hours</a> <!-- the destination, further down --> <h2 id="hours">Opening hours</h2>
Two rules for id: it must be unique on the page — two elements can't share one, any more than two houses on one street can share a number — and it should follow the filename rules from Module 0.3: lowercase, hyphens, no spaces.
The link text is the whole game
Remember from Module 1.2 that screen reader users can pull up a list of every heading on a page? They can do exactly the same with links. Now picture that list on a typical small-business site:
What a screen reader lists
click here click here read more read more read more here link
Seven links, zero information. Every one has to be opened to find out where it goes.
What it should list
fall menu catering inquiries our Portland roastery wholesale pricing (PDF, 2 MB) directions to the Pearl District shop opening hours contact us
Seven links, each one understandable with no surrounding sentence at all.
Read the link text on its own, with the sentence around it removed. Does it still tell you where you'll end up? If not, rewrite it. This single habit fixes accessibility, helps search ranking — Google reads link text to learn what the destination page is about — and makes the page easier for everyone to skim.
Rewrite it
Four real link patterns. In each option, the underlined words are the link. Pick the best version of each.
New tabs: almost never
Adding target="_blank" makes a link open in a new tab. Beginners love it for external links — "so they don't leave my site". Resist it.
Opening a new tab takes a decision away from the visitor, breaks their Back button, and disorients anyone using a screen reader or a phone, where a new tab can be nearly invisible. People who want a new tab already know how to get one: middle-click, or Ctrl/Cmd + click. Let them choose.
The honest exceptions are narrow: a help link in the middle of a half-filled form, where leaving the page would lose their work; or a PDF they'll want open alongside the page. When you do use it, say so in the link text — "Size guide (opens in new tab)" — so nobody is surprised.
You will often see rel="noopener" written alongside target="_blank". It stops the new page from reaching back and tampering with yours. Modern browsers now apply it by default, but writing it is harmless and still common in professional code.
A link goes somewhere. A button does something.
One distinction that separates professionals from everyone else, and that you'll lean on for the rest of the manual:
- Use
<a>when clicking takes you to a different place — another page, another site, a section further down. It gets a URL; it can be bookmarked, shared, opened in a new tab. - Use
<button>when clicking makes something happen here — submit a form, open a menu, add to cart, play a video. That's JavaScript's territory, from Phase 4.
Using a link as a button, or a button as a link, looks identical on screen and breaks keyboard users, screen readers and the browser's own features in quietly infuriating ways.
Navigation is a list of links
The bar of links across the top of almost every website is, structurally, just the list you learned in Module 1.2 — wrapped in an element that announces "this is the site's navigation":
<nav>
<ul>
<li><a href="index.html" aria-current="page">Home</a></li>
<li><a href="menu.html">Menu</a></li>
<li><a href="locations.html">Locations</a></li>
</ul>
</nav>
aria-current="page" marks the link to the page you're already on, so a screen reader announces "current page" — and in Phase 2 you'll use it to underline or highlight the active item. You'll learn <nav> and its relatives properly in Module 1.5; for now, recognize the shape.
Three things beginners get wrong
1. "Click here." The most common link text on the internet, and the least useful. The words should name the destination.
2. Forgetting https:// on external links. <a href="www.nps.gov"> looks right, and sends people to yoursite.com/www.nps.gov — a file that doesn't exist. Every link to another site starts with https://.
3. Opening everything in a new tab. It feels like keeping visitors; it actually takes control from them. Default to the same tab.
Words you now own
- hyperlink
- A clickable reference from one document to another. Just "link" in conversation.
- <a> — anchor
- The HTML element that makes a link.
- href
- The attribute holding the destination.
- link text
- What's between the tags: what people read, click and hear.
- absolute URL
- A full address starting with
https://. Needed for any other site. - id
- A unique name on an element, so a link can jump to it with
#. - mailto: / tel:
- Links that open an email draft or dial a phone number.
- target="_blank"
- Opens the link in a new tab. Use rarely, and say so.
- aria-current
- Marks the link to the page you're already on.
Turn one page into a small website.
What you should see — one way to do it
The nav, on both pages
<nav>
<ul>
<!-- on index.html -->
<li><a href="index.html" aria-current="page">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</nav>
On about.html, move aria-current="page" to the About link instead.
Jump links and their targets, on index.html
<p> <a href="#learning">What I'm learning</a> · <a href="#contact">How to reach me</a> </p> … <h2 id="learning">What I'm learning</h2> … <h2 id="contact">How to reach me</h2>
External and email links
<a href="https://developer.mozilla.org/">MDN Web Docs</a> <a href="mailto:maria@example.com? subject=Hello%20from%20your%20site"> Email me </a>
When you broke the link
Clicking abuot.html showed a "not found" or "cannot find" page from Live Preview — the browser asked for a file that doesn't exist. Fix the spelling and it works again.
Six questions. Four correct to move on.
"The href is where it goes, the text is what people read. Other sites need https. Link text names the destination. A link goes somewhere; a button does something." Your pages now point at each other — which means, in the literal sense Tim Berners-Lee meant it, you've built a web.