Skip to content
Tutorials Center
My learning

Topics

Lesson 94 of 139 ยท UI Components

Pagination and Breadcrumb Styling

Style pagination bars with clear current and disabled states, breadcrumbs with accessible separators, and joined button groups and segmented controls in CSS.

Some of the most common navigation on the web is also the smallest: the row of page numbers under search results, the "Home / Courses / CSS" trail above an article, and the cluster of joined buttons in a toolbar. These components are simple rows of links or buttons, but users rely on them to know where they are and where they can go next.

In this lesson you will style all three. You'll learn how to mark the current page so both eyes and screen readers can find it, how to draw separators that aren't read aloud, how to join buttons into a seamless group, and how to keep everything usable on a narrow phone screen.

Pagination: the markup first

Pagination is navigation, so it lives in a <nav> with a label that tells it apart from the main menu. Inside, an ordered list of links works well:

HTML
<nav class="pagination" aria-label="Pagination">
  <ol>
    <li><a href="?page=2" rel="prev">Previous</a></li>
    <li><a href="?page=1">1</a></li>
    <li><a href="?page=2">2</a></li>
    <li><a href="?page=3" aria-current="page">3</a></li>
    <li><a href="?page=4">4</a></li>
    <li><span class="gap">โ€ฆ</span></li>
    <li><a href="?page=12">12</a></li>
    <li><a href="?page=4" rel="next">Next</a></li>
  </ol>
</nav>

Three details make it accessible:

  • aria-label="Pagination" names the landmark, so screen reader users hear "Pagination, navigation" and can jump straight to it.
  • aria-current="page" marks the current page. Screen readers announce "current page", and it doubles as a perfect styling hook. No extra active class needed.
  • The ellipsis is plain text, not a link, because it doesn't go anywhere.

Number links like "3" are short. Some screen readers announce them as just "3, link", which is usually clear enough inside a navigation called "Pagination". If you want to be more explicit, add visually hidden text: <a href="?page=3"><span class="visually-hidden">Page </span>3</a>.

Styling the bar

The list becomes a flex row. Each link gets a minimum size so even a single digit is a comfortable target, and the current page gets a strong, filled style:

CSS
.pagination ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  list-style: none;
  padding: 0;
}
.pagination a {
  display: grid;
  place-items: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding-inline: 0.75rem;
}
.pagination [aria-current="page"] {
  background: #4f46e5;
  color: white;
}

display: grid with place-items: center centers the number in the box in two lines. The min-width rather than width lets "Previous" and "Next" grow to fit their text.

A pagination bar

On the first page there's nothing before it, so "Previous" should look and act unavailable. Links have no disabled attribute. The cleanest approach is to remove the href: an <a> without href isn't focusable or clickable, and you can style it with a:not([href]). Adding aria-disabled="true" makes the state explicit for assistive technology. Some designs hide the link completely instead; that also works, but a dimmed link keeps the bar from jumping around between pages.

Tabular numbers

font-variant-numeric: tabular-nums gives every digit the same width, so "11" and "18" are equally wide and the buttons don't change size as the numbers change. It's a small touch that also helps in tables and timers.

Pagination on small screens

A row of twelve page links doesn't fit on a phone. flex-wrap: wrap keeps it from overflowing, but two rows of numbers look messy. A better pattern is to show fewer items on narrow containers: keep Previous, Next and the current page, and replace the rest with a "Page 3 of 12" label.

A container query does this based on the space the component actually has, not the screen width:

Responsive pagination with a container query

The dashed box uses resize: horizontal so you can test the breakpoint by dragging. margin-inline-start: auto on the last item pushes "Next" to the right edge, a handy flexbox trick.

A breadcrumb trail shows where the current page sits in the site's hierarchy: Home โ€บ Courses โ€บ CSS โ€บ Pagination. It's especially useful on large sites where people arrive from search engines deep inside a section.

The markup is a labeled <nav> with an ordered list (order matters here: each step is inside the previous one), and the last item marked as the current page:

HTML
<nav class="breadcrumbs" aria-label="Breadcrumb">
  <ol>
    <li><a href="/">Home</a></li>
    <li><a href="/courses">Courses</a></li>
    <li><a href="/css">CSS</a></li>
    <li><a aria-current="page">Pagination</a></li>
  </ol>
</nav>

Separators that screen readers skip

The separator characters (/, โ€บ or >) are decoration. If they're typed into the HTML, screen readers read them out: "Home, slash, Courses, slashโ€ฆ". Add them with CSS instead, on every item except the first:

CSS
.breadcrumbs li + li::before {
  content: "โ€บ" / "";
}

The part after the slash is the alternative text for generated content. An empty string tells assistive technology to skip the character entirely. Browsers that don't understand the / "" syntax drop the whole declaration, so write a plain content: "โ€บ"; line just before it as a fallback.

Breadcrumbs with CSS separators

The second trail uses clip-path to cut each item into an arrow shape, a style often used for checkout steps. The current page is an <a> without href, so it isn't a link to itself.

Long trails

Deep hierarchies can produce trails wider than a phone. Options, from simplest to fanciest:

  • Wrap onto several lines (flex-wrap: wrap, as above). Always works.
  • Truncate long labels with max-width, overflow: hidden, white-space: nowrap and text-overflow: ellipsis on each link (see Text Wrapping).
  • Scroll horizontally with overflow-x: auto on the list, keeping it on one line.
  • Show only the parent ("โ€น Back to CSS") on small containers, using a container query like the pagination demo.

Breadcrumbs also help search engines. Adding BreadcrumbList structured data lets search results display the trail instead of a raw URL; see Structured Data.

Button groups and segmented controls

A button group joins related buttons into one block: text alignment buttons in an editor, or "Day / Week / Month" view switchers. The trick is to remove the space between them, overlap their borders by one pixel so they don't double up, and round only the outer corners:

CSS
.group { display: inline-flex; }
.group > * + * { margin-inline-start: -1px; }  /* share the border */
.group > * { border-radius: 0; }
.group > :first-child { border-start-start-radius: 8px; border-end-start-radius: 8px; }
.group > :last-child  { border-start-end-radius: 8px; border-end-end-radius: 8px; }

The logical radius properties keep the rounded corners on the correct outer edges in right-to-left languages too.

When only one option can be active, as in a view switcher, that's a segmented control: radio buttons in disguise. Using real radio inputs gives you arrow-key navigation and correct announcements for free:

A button group and a segmented control

Notes on the demo:

  • role="group" with aria-label tells screen readers the buttons belong together. The radio version uses <fieldset> and <legend>, which do the same job natively.
  • z-index on hover and focus lifts the active button so its border and focus ring aren't hidden under its neighbor's overlapping edge. Each button needs position: relative for z-index to apply.
  • The radios are hidden visually but still focusable. opacity: 0 keeps them in the accessibility tree and the tab order, unlike display: none. Their :checked and :focus-visible states style the <span> that follows them.
  • The <label> tags are written with no whitespace between them, because inline-block elements otherwise get a small gap from the spaces in the HTML.

For a toggle button that stays pressed (like Bold in an editor), use a <button> with aria-pressed="true" and style [aria-pressed="true"].

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How should you mark the current page in pagination or breadcrumbs?

    aria-current="page" tells screen readers which item is current, and you can style it with an attribute selector.
  2. 2. Why add breadcrumb separators with ::before instead of typing them in the HTML?

    With content: "โ€บ" / "", the separator is visible but skipped by assistive technology.
  3. 3. What does font-variant-numeric set to tabular-nums do in a pagination bar?

    Tabular figures are all the same width, so pages like 11 and 18 produce equally wide buttons.
  4. 4. In a joined button group, why does the hovered button get a z-index?

    Buttons overlap by one pixel to share a border. Raising the active one keeps its full outline visible.
  5. 5. Which markup is best for a "Day / Week / Month" control where exactly one option is active?

    Radios give single selection, arrow-key navigation and correct announcements without any JavaScript.

Summary

  • Pagination and breadcrumbs are navigation: use a labeled <nav> and an ordered list of links.
  • Mark the current item with aria-current="page" and style it with [aria-current="page"].
  • Give page links a comfortable min-width/min-height, center them with grid, and use tabular-nums for steady widths.
  • Disable a link by removing its href (plus aria-disabled="true"), and simplify pagination on narrow containers with a container query.
  • Add breadcrumb separators with ::before and empty alternative text (content: "โ€บ" / ""), keeping a plain fallback line.
  • Join button groups with negative margins and outer-corner radii, raise the active item with z-index, and build single-choice segmented controls from radio inputs.

Next: Spinners, Loaders and Skeletons, where you show people that something is on its way.