Sub topic 1
Start with semantic HTML: nav, ul, li and a
A navigation bar looks like a row of links, but the HTML underneath decides whether it works for keyboards, screen readers, search engines and your own future CSS. This chapter builds only the markup. Styling comes in later chapters. By the end you will know which four elements make up the structure, why each one is there, and which mistakes cause trouble later.
Prerequisites
This chapter assumes you already know:
- Basic HTML elements and attributes, including how to write an
aelement with anhref. - Basic CSS selectors and properties. This chapter uses almost no CSS, but the rest of the tutorial does.
- The CSS box model (margin, padding, border).
You do not need any JavaScript or Flexbox knowledge yet.
Why a navigation bar starts as a list
A navigation bar is a set of related links. HTML already has an element for a set of related items, which is the list. Using a list gives you three things without extra work:
- A screen reader can announce "list, 4 items" and let the user jump between items.
- The links share one parent, so a single CSS rule can target all of them.
- Without CSS, the page still reads as a sensible vertical list of links.
You could build the same visual result with a row of div or span elements. It would look identical in a browser, but a screen reader would see only unrelated pieces of text, and you would lose all the structure listed above. Semantic markup means choosing elements for what the content is, not for how it looks. Appearance is CSS's job.
The four elements
nav
The nav element is a landmark. A landmark is a region of the page that assistive technology can list and jump to directly. Screen reader users often open a list of landmarks first, then move straight to "navigation" and skip the header and article.
The nav element does not draw anything. By default it behaves like a div. Its value is the meaning it adds.
Use nav for major blocks of navigation links, such as the main site menu, a table of contents, or breadcrumbs. Do not wrap every group of links in one. A short row of links in a footer, or a list of "related articles" inside the body text, usually does not need to be a landmark.
ul
The ul element is an unordered list. The order of the links is not part of their meaning, so ul is the usual choice for a menu. If the order were the point, for example the steps of a multi-page checkout, ol (ordered list) would fit better. Most site menus use ul.
By default a browser adds bullets and left padding to a ul. You will remove both in the next chapter. Keep the element anyway. The bullets are only a default style, but the list semantics are what assistive technology uses.
li
The li element is a list item. The only valid direct children of a ul are li elements. Each li holds one menu entry, which here is one link.
Later in the tutorial, the li also becomes the place where a submenu lives, because a nested list goes inside the li of its parent link.
a
The a element is an anchor, which means a link. It carries the href attribute, the address the link points to. Links are focusable by default, so users can reach them with the Tab key and activate them with Enter. A real a with an href gives you this for free.
The first version
Here is the complete markup for a four-link bar.
<nav aria-label="Main">
<ul class="nav-list" id="nav-list">
<li><a href="/" aria-current="page">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Read it from the outside in:
navmarks the whole region as navigation. Itsaria-labelgives the landmark a name.ulgroups the entries. Itsclassis a styling hook for CSS, and itsidlets a script or anaria-controlsattribute refer to the list later.- Each
liholds one entry. - Each
ais the clickable link, and its text is what the user sees and what a screen reader reads.
The aria-current="page" attribute on the first link says "this link points to the page you are on now." You will use it to style the current page in a later chapter. Include it now so the markup is already complete.
The next block puts the bar in a minimal full page, which you can save as index.html and open in a browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home</title>
</head>
<body>
<header>
<nav aria-label="Main">
<ul class="nav-list" id="nav-list">
<li><a href="/" aria-current="page">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Welcome</h1>
<p>Page content goes here.</p>
</main>
</body>
</html>Opened as a local file, the links will not go anywhere useful, because /products points at the root of your file system and not at a web server. That is fine for now. The structure is what matters. When you serve the page from a web server, root-relative links resolve against the site.
With no CSS, you should see a bulleted vertical list of four links. That is the correct result. It proves the markup stands on its own.
How the pieces nest
The diagram shows the tree the browser builds from the page above. The nav sits inside the header, and each link sits inside its own list item.
Every later chapter in this tutorial attaches to this tree. Flexbox goes on the ul, padding goes on the a, and a submenu will be a second ul inside one of the li elements.
Labeling the landmark
The aria-label="Main" attribute gives the nav an accessible name. A screen reader announces it as "Main navigation". With a single nav on the page, the label is optional but harmless. It becomes necessary when a page has more than one:
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/docs">Docs</a></li>
</ul>
</nav>
<nav aria-label="Breadcrumb">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/docs">Docs</a></li>
</ul>
</nav>Without distinct labels, a user hears "navigation, navigation" and cannot tell which is which. Keep the label short and do not include the word "navigation", because the screen reader already adds the landmark's role.
Choosing href values
The href value decides where the link goes. Three forms are common in a navigation bar:
| Form | Example | Resolves against | Use it for |
|---|---|---|---|
| Root-relative | `/products` | The site's root | Links inside your own site, safe from any page depth |
| Document-relative | `products.html` | The current page's folder | Small static sites, local files |
| Absolute | `https://example.com/` | Nothing, it is complete | Links to other sites |
Root-relative links are a good default for a navigation bar. The same markup works on /index.html and on /blog/2026/post.html. A document-relative link such as contact.html would break on the second page, because the browser would look for /blog/2026/contact.html.
Common errors
These mistakes are easy to make and hard to spot visually, because the page still looks fine.
| Mistake | What goes wrong | Fix |
|---|---|---|
| Putting `a` elements directly inside `ul` | Invalid HTML. Only `li` is allowed as a direct child. Screen readers may report the list wrongly. | Wrap each link in an `li`. |
| Using `div` or `span` with a click handler instead of `a` | No keyboard focus, no Enter activation, no "open in new tab", and no link announcement. | Use `a` with an `href`. |
| Using `a` without `href` | The element is not focusable and is not announced as a link. | Add an `href`. |
| Using `button` for page-to-page navigation | Buttons perform actions. Links go places. Users expect middle-click and right-click to work on links. | Use `a` for navigation, `button` for actions. |
| Wrapping the list in `nav` twice or wrapping all page content in `nav` | Landmark lists become noisy and the real navigation is hard to find. | One `nav` per block of major navigation links. |
| Using `br` or ` ` between links to space them | Spacing is mixed into the content and breaks when you restyle. | Leave the markup clean and space the links with CSS. |
| Adding `role="navigation"` to `nav` | Redundant, since `nav` already has that role. | Remove the attribute. |
| Several `nav` elements with no labels | Users cannot tell the landmarks apart. | Give each a different `aria-label`. |
Edge cases
- Does the nav have to be inside
header? No. Anavinsideheaderis common, and anavdirectly underbodyis also valid. Choose the placement that matches your page layout. - Can the
lihold something besides a link? Yes. It can hold a nested list for a submenu, or a link plus a button. Keep one primary link perli. - What about a "Skip to content" link? It is a normal
athat points at an id on the page, such ashref="#content". It usually sits before thenav. It is not part of the list. - What if my site has only two links? Still use the list. The cost is two extra lines, and the markup stays consistent with the rest of the site.
- Should the current page be a link? Many sites keep it as a link with
aria-current="page". Some remove the link. Keeping it is safer, because the layout does not shift and the link stays focusable. - Does
ulneed aclassorid? Theclassandidare only hooks. Theidis needed later for the mobile toggle button, so adding it now saves an edit.
Summary
The structure is nav containing ul, containing li, containing a. Each element carries one job: landmark, list, entry, link. The aria-label names the landmark, aria-current="page" marks where the reader is, and href values should be root-relative for in-site links. In the next chapter you will remove the default bullets and spacing from the list.
Exercise
A teammate writes <ul><a href="/">Home</a><a href="/about">About</a></ul> and says it works because it looks fine in the browser. Name two reasons this markup is wrong and show the corrected version.
Show answer
First, a elements are not valid direct children of ul. Only li is allowed. Second, assistive technology cannot count the list items, so it cannot announce them as a list of two entries. The corrected version is <ul><li><a href="/">Home</a></li><li><a href="/about">About</a></li></ul>. It should also be wrapped in a nav element, ideally with an aria-label.
Exercise
A page has a main menu and a breadcrumb trail, and both are wrapped in nav with no other attributes. What problem does a screen reader user have, and how do you fix it?
Show answer
The user hears two landmarks both announced as "navigation" and cannot tell which is the main menu. Give each a distinct label, for example aria-label="Main" on the menu and aria-label="Breadcrumb" on the trail.
Exercise
Your site has a page at /blog/2026/post.html and a link written as href="contact.html". Where does the browser send the user, and what href fixes it for every page?
Show answer
The browser resolves it against the current folder and requests /blog/2026/contact.html, which does not exist. Using the root-relative href="/contact" (or /contact.html, matching how your server names the page) works from any page.