How the anchor element, relative and absolute paths, and navigation patterns turn separate pages into one connected, navigable website
Imagine a library where every book exists, but none of them reference any other. No footnotes. No "see also." No card catalog connecting related works. Every reader would need to already know exactly which book held the answer, because nothing in the building pointed anywhere else. Finding information would depend entirely on luck or memory.
The web does not work that way, and the reason is a single idea so simple it is easy to take for granted: any document can point directly to any other document, anywhere, and a reader can follow that pointer with one click. This idea is called the hyperlink, and it is the feature that gives the World Wide Web its name. In Chapters 5 and 6 you learned how to structure a single page with HTML. This chapter teaches you how to connect pages — to each other, to other websites, and to specific points within a page — and how to organize those connections into a website that makes sense to the people who use it.
A small website has five pages: Home, About, Lessons, Resources, and Contact. A visitor lands on the Resources page from a search engine. How do they get to the other four pages without typing a new address? How does the site let them know which page they are currently viewing? How would a much larger site — one with hundreds of pages organized into categories and subcategories — keep visitors from getting lost? Every one of these questions is answered with the same underlying tool: the link. By the end of this chapter, you will know how to write links correctly, open them responsibly, and arrange them into a navigation system that holds an entire website together.
By the end of this chapter, you should be able to:
href attribute.id attributes and fragment identifiers.nav, ul, li, and a elements.a element; the href attribute; link content; common anchor attributes; default browser link stylingtarget="_blank"; the rel="noopener noreferrer" pattern; mailto: and tel: links; writing meaningful link textid attribute; fragment identifiers; jump links within a page; skip-to-content links for accessibilitynav element; list-based navigation patterns; indicating the current page; navigation as a landmarkEvery HTML page you built in Chapters 5 and 6 was, on its own, an island. It had structure, headings, and meaning, but nothing connected it to anything else. The feature that turns a collection of separate documents into a web is the hyperlink — a piece of text, an image, or another element that, when activated, takes the user to a different location: another page, another part of the same page, a file, or an external resource.
The idea of linked documents predates the web itself. Researchers had imagined systems of cross-referenced information for decades before any of it was built. What made the World Wide Web different was that it combined this idea with a simple, universal way to address any document on any connected computer, and a simple piece of HTML markup — the anchor element, which you will meet in the next section — that any author could use to point to it.
Links matter for two audiences at once. For people, links are how they move through information: from a search result to an article, from a homepage to a product page, from one paragraph to a related idea. For machines, links are how search engines discover new pages in the first place — a search engine finds your site largely by following links to it, and finds the rest of your site by following the links inside it. A page with no incoming links is difficult for anyone, human or machine, to find at all.
The web is named after its structure, not its appearance. If you drew every web page as a dot and every link as a line connecting two dots, the result would look like a tangled, sprawling web — millions of documents, each pointing to others, with no single center and no required order. This chapter is about learning to add your own pages to that structure correctly, so that they are easy to find, easy to move through, and easy to maintain.
It can help to think of a website not as a stack of pages but as a small graph: each page is a node, and each link is an edge connecting two nodes. As you work through this chapter, try sketching the graph of any website you visit. Notice which pages have many incoming links (usually the homepage) and which have only one or two.
HTML creates a link with the anchor element, written as <a>. The anchor element needs one essential attribute to function as a link: href, short for "hypertext reference." The value of href is the destination — the path or address the browser should go to when the link is activated.
Whatever content sits between the opening <a> tag and the closing </a> tag becomes the clickable link. Most often this is text, but it can also be an image or a small group of elements. Whatever it is, that content is what the user sees and clicks.
<p> You can learn more about semantic HTML on the <a href="about.html">About page</a>. </p>
An anchor element without an href attribute is not a functioning link — browsers will display it without the usual link styling and it will not be reachable by keyboard the way a real link is. If an element should behave like a link, it needs href. If it should trigger a script action with no destination, it is usually better written as a <button>, a distinction Chapter 9 returns to.
| Attribute | Purpose | Example |
|---|---|---|
href | The destination of the link. Required for the element to act as a link. | href="lessons.html" |
target | Where to open the destination — the same tab or a new one. | target="_blank" |
rel | Describes the relationship between the current page and the linked page; also used for security and SEO signals. | rel="noopener noreferrer" |
download | Suggests that the browser download the linked file rather than navigate to it. | download |
title | Extra descriptive text, usually shown as a tooltip on hover. | title="Opens in a new tab" |
By default, browsers style links in a recognizable way — typically underlined and colored, with a different color once a link has been visited. This default styling exists so that links are visually distinguishable from ordinary text without any extra effort from the page author. You will learn to style links deliberately, including their hover and visited states, when Chapter 12 introduces pseudo-classes. For now, leave the default styling alone and focus on writing correct, working href values.
Chapter 3 introduced relative paths for linking stylesheets, scripts, and images. The same idea applies directly to links between pages. A relative link describes a destination relative to the location of the current file — not as a complete address, but as directions from "here."
Three patterns cover the large majority of relative links you will write in a typical project.
about.html sits in the same folder as the current page, link to it by filename alone: <a href="about.html">About</a>.<a href="lessons/intro.html">Intro Lesson</a>.<a href="../index.html">Home</a>. Each additional ../ moves up one more level.Relative links have an important advantage: because they describe a path rather than a complete address, an entire project folder can be copied, renamed, or moved to a new server, and every internal link will continue to work — provided the files keep the same positions relative to one another. This is why Chapter 3 emphasized clean, consistent project structure: relative links depend on it directly.
Relative links describe a path from the current file, not from the project's root folder. A link that works correctly from index.html may need a different path when the same link is copied into a page stored inside a subfolder. When you move a file, check every relative link in it — both links going out of the file and any links elsewhere that point into it. Chapter 4 will show you how to use developer tools to find broken links quickly.
An absolute link uses a complete URL: a protocol such as https://, a domain name, and usually a path. Chapter 2 explained URLs in depth as part of how the web works; here, the focus is simply on when and how to use a full URL inside an anchor element.
Relative links only make sense for files that live inside your own project, because they describe a path through your own folder structure. To link to a page that lives anywhere else — a different website entirely — you need the complete address.
<p> Read the official specification on the <a href="https://www.w3.org/">W3C website</a>. </p>
If the destination is a file inside your own project, use a relative link. If the destination is on a different website, use an absolute link with the full address, including https://. Mixing the two up is rare once you ask one question before writing any href: "Does this file live inside my project folder, or somewhere else?"
One more situation calls for an absolute link even within your own site: if you ever reference your own pages from outside contexts — an email, a social post, another company's website — those references need the full address, because there is no "current file" for a relative path to be relative to.
A link does more than point somewhere; it makes a small decision on behalf of the user about how they will get there. Two decisions matter most: whether the link opens in the same tab or a new one, and whether the link's text tells the user what to expect.
target AttributeBy default, a link replaces the current page. Adding target="_blank" opens the destination in a new tab instead, leaving the original page open. This is sometimes useful — for example, linking to an external reference that a reader might want to consult without losing their place — but it should be used deliberately, not by habit. Opening too many links in new tabs leaves users with a cluttered row of tabs and can be disorienting, especially for people using screen readers, who are not always told that a new tab has opened.
When you do use target="_blank" for a link to another website, pair it with rel="noopener noreferrer". Without it, the newly opened page can, in some browsers, gain a limited ability to access and redirect the original tab — a small but real security and privacy concern. noopener blocks that access; noreferrer additionally withholds referrer information from the destination site.
<a href="https://www.example.org/" target="_blank" rel="noopener noreferrer"> Visit Example.org </a>
Two special href patterns let a link launch a different application instead of navigating to another page. A mailto: link opens the user's email program with a new message addressed to the given address. A tel: link, most useful on phones, starts a call.
<a href="mailto:[email protected]">[email protected]</a> <a href="tel:+15551234567">(555) 123-4567</a>
The words inside a link should make sense even if a reader sees them out of context — which is exactly how many screen reader users browse, by pulling up a list of every link on a page in isolation from the surrounding sentences. Link text such as "click here" or "read more" tells that reader nothing about where the link goes.
For our pricing, <a href="pricing.html">click here</a>. — out of context, "click here" is meaningless. Prefer: View our <a href="pricing.html">pricing details</a>. — the link text itself describes the destination.
Not every link needs to leave the current page. A link can also jump to a specific location within the same page — or within a different page — using a fragment identifier: an href value that begins with a hash symbol, #, followed by the value of an id attribute somewhere on the page.
Every id attribute value must be unique within a page. Once an element has an id, a link anywhere can jump straight to it.
<nav> <a href="#ingredients">Ingredients</a> <a href="#instructions">Instructions</a> </nav> <section id="ingredients"> <h2>Ingredients</h2> <!-- content --> </section> <section id="instructions"> <h2>Instructions</h2> <!-- content --> </section>
A fragment identifier can also follow a filename to jump to a location on a different page: href="resources.html#video-guides" opens resources.html and scrolls directly to the element with id="video-guides".
Many sites include a "skip to main content" link as the very first focusable element on the page, hidden visually but reachable by keyboard, linking to #main-content on the same page. This lets a keyboard or screen-reader user bypass a long repeated navigation menu and jump straight to the unique content of the page. Chapter 29 returns to this pattern in more depth as part of accessibility practices.
A breadcrumb trail is a small row of links, usually placed near the top of a page, that shows the path from the site's home page down to the page currently being viewed. The name comes from the fairy tale in which a trail of breadcrumbs marks the way back. On a website, a breadcrumb trail marks the way back up the site's hierarchy.
<nav aria-label="Breadcrumb">
<ol>
<li><a href="index.html">Home</a></li>
<li><a href="lessons.html">Lessons</a></li>
<li>Introduction to Selectors</li>
</ol>
</nav>
Notice that the trail uses an ordered list, since the sequence from home to current page genuinely matters, and that the final item — the current page — is plain text, not a link, since linking to the page a visitor is already on serves no purpose.
Breadcrumbs earn their place on sites with real depth — a store with categories and subcategories, a documentation site with nested topics, a multi-step lesson library. A small five-page site, like the Student Learning Site running through this textbook, does not need a breadcrumb trail; its full set of pages already fits comfortably in a single navigation menu. Adding breadcrumbs to a flat, shallow site adds visual clutter without adding clarity.
Information architecture is the practice of organizing and labeling the content of a site so that people can find what they need. It is a planning activity that happens before — and continues alongside — writing any HTML. A site with strong information architecture feels obvious to navigate; a site with weak information architecture leaves visitors clicking around, unsure where to look.
Two broad patterns describe most small to medium sites:
| Pattern | Description | Good Fit For |
|---|---|---|
| Flat structure | A small number of pages, all reachable directly from one main navigation menu, with no deep nesting. | Small business sites, portfolios, personal sites, course companion sites |
| Hierarchical structure | Pages organized into categories and subcategories, often several levels deep, usually paired with breadcrumbs. | Large documentation sites, online stores, news archives, large institutions |
Before writing a single file, it helps to sketch a site map — a simple diagram or outline listing every planned page and how they connect. Restructuring a site map on paper costs minutes; restructuring a site after dozens of pages already link to one another costs hours of careful path-fixing. This is the same lesson Chapter 3 taught about project folders, applied one level up: plan the shape of the whole site, not just the shape of one folder.
This is a flat structure: every page is one click from every other page through the same navigation menu. That choice is deliberate, not accidental — for a five-page learning site, a flat structure is simpler to build, simpler to maintain, and easier for a visitor to understand at a glance than a hierarchy would be.
Every idea in this chapter comes together in one practical task: building a small set of pages that link to each other correctly and consistently. This section walks through that process from start to finish, using the Student Learning Site site map from Section 7.9.
web-project/ index.html about.html lessons.html resources.html contact.html
<title> for every page.<nav> markup from Section 7.7 once, then copy it into every page. Because all five files sit in the same folder, every link in the menu can use a same-folder relative path: href="about.html", href="lessons.html", and so on.aria-current="page" to the one navigation link that matches that page, and update it as you copy the menu across files.id attributes to major sections and a short set of jump links at the top, following Section 7.6.A site built this way — small, flat, consistently linked, and carefully tested — is exactly the foundation the rest of this textbook builds on. Part III adds styling and layout to these same pages. Part IV adds JavaScript interaction. Part V revisits navigation again, in Chapter 26, to show how to keep a shared header and footer consistent without duplicating effort across many more pages than five.
<a>, creates a link using the required href attribute. Additional attributes such as target, rel, download, and title control link behavior. Browsers style links by default; deliberate link styling waits for CSS.../. Relative links keep working when an entire project moves, provided file positions relative to one another stay the same.target="_blank" opens a link in a new tab and should be paired with rel="noopener noreferrer" for security. mailto: and tel: links launch other applications. Link text should make sense out of context, avoiding vague phrases like "click here."#id, link to a specific element on a page using its id attribute. This pattern supports jump links, tables of contents, and accessible skip-to-content links.<nav>, almost always using an unordered list. aria-current="page" marks the active page for both sighted and assistive-technology users.<nav>. Breadcrumbs help on deep, hierarchical sites and add unnecessary clutter on small, flat ones.<a>, used to create a hyperlink._blank.noopener noreferrer.href begins with mailto:, opening the user's email program with a new message.# that points to an element with a matching id attribute on a page.<nav> and an unordered list, that lets visitors move between a site's major pages or sections.Answer these questions before beginning the full review questions. They check basic understanding, not deep analysis.
target="_blank" do, and what attribute should usually accompany it?href — typically an anchor element — behaves like a real link: reachable by keyboard, navigable to a destination, and announced as a link by assistive technology. Styling something to look clickable does not make it a link. If it has a destination, use <a href="...">; if it triggers behavior with no destination, use a <button>, covered further in Chapter 21.href value can point to two completely different destinations depending on where the file using it is located. Moving a file to a different folder without updating its links — or the links pointing to it — is one of the most common sources of broken links.target="_blank" deliberately, and pair it with rel="noopener noreferrer".Write the correct relative href value for each situation. No browser required — work through these on paper or in a text file first.
index.html in the project root, link to contact.html, which is also in the project root.index.html in the project root, link to intro.html, which is inside a subfolder named lessons.lessons/intro.html, link back to index.html in the project root.lessons/intro.html, link to a sibling lesson page, lessons/selectors.html.lessons/css/grid.html (two folders deep), link back to index.html in the project root.Read the navigation markup below, then answer the questions that follow.
<nav aria-label="Main">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html" aria-current="page">About</a></li>
<li><a href="lessons.html">Lessons</a></li>
<li><a href="https://www.mgulibrary.org/" target="_blank">MGU Library</a></li>
</ul>
</nav>
<nav> rather than left as a plain <div>?Each example below contains one link that will not work as intended. Identify the problem and explain the fix.
about.html in the project root contains: <a href="resources/guide.html">Guide</a> — but there is no resources folder in the project; the file guide.html actually sits in the project root, alongside about.html.lessons/intro.html contains: <a href="index.html">Home</a> — intended to link back to the project's root index.html.<a>Contact Us</a> with no further attributes, and the author expected it to link to contact.html.<a href="#contact-form">Jump to Form</a>, but no element on the page has id="contact-form".No coding required for this activity — only planning and reasoning.
target="_blank" do? What attribute commonly accompanies it, and why?<nav> with an unordered list. What does the extra structure communicate, and to whom?lessons subfolder. List every kind of link in the project that might now be broken, and explain, for each kind, what needs to change.<a href="https://www.partner-site.org/" target="_blank">Visit our partner</a>. Identify one improvement you would make to this line and explain why, using ideas from Section 7.5.<nav> and an unordered list, for a four-page site of your choosing. Mark the current page on the "Home" version of the menu using aria-current="page".id, and a small set of jump links at the top that lets a reader skip directly to any section.href attribute.target="_blank" and why it should be paired with rel="noopener noreferrer".id attributes and fragment identifiers.nav, ul, li, and a.Chapter 7 connected your pages to each other and to the rest of the web. Chapter 8 turns to a different kind of content: images, audio, video, and embedded media. You will learn how to choose appropriate image formats, write the img element with correct src and alt attributes, caption visual content with figure and figcaption, and think carefully about file size, performance, and copyright. Just as this chapter treated links as more than decoration, Chapter 8 treats images and media as content that must support meaning, load efficiently, and remain accessible to every visitor.