MGU Computer Science Series — Web Development: HTML, CSS, and JavaScript
Part II: HTML — Structure and Meaning
Anchors · Paths · Navigation · Information Architecture
Chapter 7 of 30
7
MGU Computer Science Series  ·  Web Development: HTML, CSS, and JavaScript  ·  Library Textbook Edition

Chapter 7:
Links, Navigation,
and Site Structure

How the anchor element, relative and absolute paths, and navigation patterns turn separate pages into one connected, navigable website

■ Part II of VII ■

■ 10 Sections  •  Chapter 7 of 30 ■

Builds on Chapters 5–6 — HTML documents, elements, and semantic structure

Chapter Introduction and Learning Objectives

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.

Opening Question

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.

10Sections
10Objectives
15Key Terms
30Total Chapters

Learning Objectives

By the end of this chapter, you should be able to:

  1. 1Explain why links are the foundational feature that distinguishes the web from a collection of isolated documents.
  2. 2Describe the purpose of the anchor element and write a correct link using the href attribute.
  3. 3Write relative links to pages within the same project, including links into subfolders and up to parent folders.
  4. 4Write absolute links to pages on other websites and explain when an absolute link is required.
  5. 5Open links responsibly, including choosing when to use a new tab and writing link text that makes sense out of context.
  6. 6Create internal page links using id attributes and fragment identifiers.
  7. 7Build a semantic navigation menu using the nav, ul, li, and a elements.
  8. 8Explain what a breadcrumb trail is and identify when a site is large enough to need one.
  9. 9Define information architecture and explain why planning a site's structure matters before writing code.
  10. 10Build a consistent, working multi-page link system across a small website project.

Sections at a Glance

The Anchor Element

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.

Example — A Basic Link
<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.

AttributePurposeExample
hrefThe destination of the link. Required for the element to act as a link.href="lessons.html"
targetWhere to open the destination — the same tab or a new one.target="_blank"
relDescribes the relationship between the current page and the linked page; also used for security and SEO signals.rel="noopener noreferrer"
downloadSuggests that the browser download the linked file rather than navigate to it.download
titleExtra 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.

Site Structure and Information Architecture

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:

PatternDescriptionGood Fit For
Flat structureA 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 structurePages 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.

Example 7.9.1
A site map for the Student Learning Site
  • HomeThe entry point. Links out to every other top-level page; nothing links into the site more often than this one.
  • AboutA single page describing the purpose of the site. No subpages needed.
  • LessonsA landing page that, in later chapters, may grow links to individual lesson pages — the beginning of a small hierarchy.
  • ResourcesA page listing external and internal resources, later powered by a JSON file in Chapter 28.
  • ContactA page containing the accessible contact form built in Chapter 9.

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.

Building a Multi-Page Link System

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.

Project Folder Structure
web-project/
  index.html
  about.html
  lessons.html
  resources.html
  contact.html
Worked Example
From site map to working links
  • PlanConfirm the site map: five pages, flat structure, one shared navigation menu, all files in the same top-level folder.
  • Build the skeletonCreate each file with the basic HTML skeleton from Chapter 5 and a meaningful <title> for every page.
  • Write one navigation menuWrite the <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.
  • Mark the current pageOn each page, add aria-current="page" to the one navigation link that matches that page, and update it as you copy the menu across files.
  • Add internal anchors where usefulOn longer pages, such as Lessons, add id attributes to major sections and a short set of jump links at the top, following Section 7.6.
  • Test every linkOpen each page in the browser and click every link in the navigation menu, confirming it lands on the correct page and that the correct link is marked as current. Chapter 4's developer tools make this faster once a site grows beyond a handful of pages.

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.

Chapter Summary

Key Terms

hyperlink
A piece of content that, when activated, takes the user to another location: a page, a part of a page, a file, or an external resource.
anchor element
The HTML element, written <a>, used to create a hyperlink.
href
The attribute on an anchor element that specifies the link's destination. Required for the element to function as a link.
relative link
A link whose destination is described as a path from the current file, rather than as a complete address.
absolute link
A link whose destination is a complete URL, including protocol and domain, usually used to link to other websites.
target attribute
An attribute that controls where a link's destination opens, such as a new browser tab when set to _blank.
rel attribute
An attribute describing the relationship between the current page and a linked page; also used for security settings such as noopener noreferrer.
mailto link
A link whose href begins with mailto:, opening the user's email program with a new message.
fragment identifier
A link destination beginning with # that points to an element with a matching id attribute on a page.
id attribute
An attribute giving an element a unique identifying name within a page, used for fragment identifiers and other targeted references.
navigation menu
A group of links, typically wrapped in <nav> and an unordered list, that lets visitors move between a site's major pages or sections.
skip link
An accessible internal link, usually the first focusable element on a page, that lets keyboard and screen-reader users jump directly to the main content.
breadcrumb trail
A row of links showing the path from a site's home page down to the current page, typically marked up as an ordered list.
information architecture
The practice of organizing and labeling a site's content so that people can find what they need.
site map
A diagram or outline listing a site's planned pages and how they connect, sketched before building begins.

Concept Check

Answer these questions before beginning the full review questions. They check basic understanding, not deep analysis.

  1. What attribute makes an anchor element function as a link, and what does its value represent?
  2. What is the difference between a relative link and an absolute link? When is each one appropriate?
  3. What does target="_blank" do, and what attribute should usually accompany it?
  4. What is a fragment identifier, and what HTML attribute does it depend on?
  5. What elements typically wrap a navigation menu's links?
  6. What does a breadcrumb trail show, and what kind of site benefits most from one?
  7. What is information architecture, and why should it be planned before a site is built?

Common Misconceptions

Misconception 1
"Any clickable-looking element is a link."
Only an element with a working 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.
Misconception 2
"Relative paths work the same no matter which file uses them."
A relative path is always relative to the file that contains it. The same 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.
Misconception 3
"Opening links in a new tab is always more convenient for users."
New tabs can help in specific situations, such as linking to a reference a reader may want to keep open, but used by default they clutter a user's browser and can confuse people using assistive technology, who are not always informed that a new tab has opened. Use target="_blank" deliberately, and pair it with rel="noopener noreferrer".
Misconception 4
"Every website needs a breadcrumb trail."
Breadcrumbs solve a specific problem: helping visitors track their position in a deep, hierarchical site. A small, flat site where every page is one click away through a single navigation menu does not have that problem, and adding breadcrumbs to it adds visual clutter without adding clarity.
Misconception 5
"Site structure can be figured out while building, one page at a time."
Some structure can certainly evolve, but planning a site map in advance — even a rough one — costs far less time than discovering, after dozens of pages already link to one another, that the structure needs to change. Information architecture is a planning discipline, not an afterthought.
ActivitiesLink Path Practice

Write the correct relative href value for each situation. No browser required — work through these on paper or in a text file first.

  1. From index.html in the project root, link to contact.html, which is also in the project root.
  2. From index.html in the project root, link to intro.html, which is inside a subfolder named lessons.
  3. From lessons/intro.html, link back to index.html in the project root.
  4. From lessons/intro.html, link to a sibling lesson page, lessons/selectors.html.
  5. From lessons/css/grid.html (two folders deep), link back to index.html in the project root.
ActivitiesNavigation Code Reading

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>
  1. Which page is the visitor currently viewing? How can you tell from the markup alone?
  2. Which link in this menu is an absolute link? How do you know?
  3. The link to the MGU Library opens in a new tab. What attribute is missing that this chapter recommends adding, and why?
  4. Why is this list of links wrapped in <nav> rather than left as a plain <div>?
ActivitiesBroken Link Debugging

Each example below contains one link that will not work as intended. Identify the problem and explain the fix.

  1. A file at 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.
  2. A file at lessons/intro.html contains: <a href="index.html">Home</a> — intended to link back to the project's root index.html.
  3. A page contains: <a>Contact Us</a> with no further attributes, and the author expected it to link to contact.html.
  4. A page contains: <a href="#contact-form">Jump to Form</a>, but no element on the page has id="contact-form".
ActivitiesSite Structure Activity

No coding required for this activity — only planning and reasoning.

  1. Sketch a site map, in outline or diagram form, for a small site of your choosing — for example, a recipe site, a hobby club site, or a personal portfolio. List every planned page and draw or describe which pages link to which.
  2. Decide whether your site map describes a flat structure or a hierarchical structure, and justify the choice in one or two sentences.
  3. Identify whether your site would benefit from a breadcrumb trail. Explain your reasoning using the guidance from Section 7.8.
  4. List the navigation menu items, in the order you would place them, and explain your ordering choice.
ReviewReview Questions

Recall and Vocabulary

  1. What HTML element creates a hyperlink, and what attribute does it require to function?
  2. Define relative link and absolute link in your own words.
  3. What does target="_blank" do? What attribute commonly accompanies it, and why?
  4. What is a fragment identifier? What attribute must exist somewhere on the page for it to work?
  5. What is a breadcrumb trail, and what list element is typically used to mark one up?
  6. What is information architecture?

Understanding and Explanation

  1. Explain why the web is sometimes described as a graph of linked documents rather than a simple stack of pages.
  2. Explain why relative links continue to work when an entire project folder is moved to a new server, while absolute links to other sites do not need to change at all.
  3. Explain why link text such as "click here" is considered poor practice, using the idea of a screen reader's link list to support your answer.
  4. Explain the difference between marking up a navigation menu as a plain list of links versus wrapping it in <nav> with an unordered list. What does the extra structure communicate, and to whom?
  5. Explain why a small, flat site generally does not need breadcrumbs, while a large, hierarchical site usually benefits from them.

Application and Analysis

  1. A student builds a five-page site entirely in one folder, then later decides to move all the lesson-related pages into a new lessons subfolder. List every kind of link in the project that might now be broken, and explain, for each kind, what needs to change.
  2. A page includes the following link: <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.
  3. A classmate argues that breadcrumbs should appear on every page of every site "just in case it grows later." Write a short response, using the distinction between flat and hierarchical structures from Section 7.9.
  4. Look back at the Student Learning Site map in Section 7.9. Suppose the site later adds ten individual lesson pages under the Lessons section. Would you keep the structure flat or shift toward a hierarchical pattern with breadcrumbs? Justify your answer.

Design and Synthesis

  1. Design the complete navigation menu markup, using <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".
  2. Write the HTML for a short page with three internal sections, each with an id, and a small set of jump links at the top that lets a reader skip directly to any section.
Chapter 7 Checklist
Use this to confirm your understanding before moving to Chapter 8
Concepts
  • I can explain why hyperlinks are the foundational feature of the web.
  • I can write a correct anchor element using the href attribute.
  • I can write relative links within the same folder, into subfolders, and up to parent folders.
  • I can write absolute links to pages on other websites.
  • I can explain when to use target="_blank" and why it should be paired with rel="noopener noreferrer".
  • I can create internal page links using id attributes and fragment identifiers.
  • I can build a semantic navigation menu using nav, ul, li, and a.
  • I can explain what a breadcrumb trail is and when a site needs one.
  • I can describe the difference between flat and hierarchical site structures.
Applications
  • I can sketch a simple site map before building a site.
  • I can build a working, consistent navigation menu across several linked pages.
  • I can write meaningful link text instead of vague phrases like "click here."
  • I can identify and fix a broken relative link by tracing its path.
Study Habits
  • I trace relative paths by hand from the file that contains them, not from the project root.
  • I test every link I write by clicking it in the browser, not just by reading the code.
  • I plan a site's structure before writing its pages, the same way I plan a folder structure before writing its files.
Preview — Chapter 8
Images, Media, and Embedded Content

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.

MGU Library Connection
  • Web Development: HTML, CSS, and JavaScript — Appendix B: HTML Reference (Links section)
  • Web Development: HTML, CSS, and JavaScript — Appendix C: Semantic HTML and Accessibility Reference
  • Companion resource: Link and Path Guide
  • Companion resource: HTML Element Reference
  • Related chapter: Chapter 3, Files, Folders, Paths, and Project Structure
  • Related chapter: Chapter 26, Navigation, Headers, Footers, and Multi-Page Sites
  • MGU Digital Literacy — background reading on web accessibility and inclusive design