Sub topic 7
The bottom tab bar
A bottom tab bar is a row of three to five top-level destinations fixed to the bottom edge of the screen. Native mobile apps use it everywhere, and many mobile websites copy it. This chapter builds one and covers the details that make it work: touch targets, safe areas, the current-page state, and content that the bar covers.
This chapter assumes you know semantic navigation markup, flexbox, and the viewport meta tag from earlier chapters. It also assumes you understand aria-current at a basic level, though it is explained briefly below.
Why a tab bar works on phones
The hamburger menu hides every destination behind one extra tap. A tab bar keeps the main destinations visible all the time. That has three effects:
- Users see where they can go without opening anything.
- Users see where they are, because the active tab is highlighted.
- Users can reach the bar with a thumb, because it sits at the bottom of the screen, where the thumb rests on a phone held in one hand.
The cost is space. The bar permanently occupies about 48 to 56 CSS pixels of vertical height, and it only fits a handful of items. If your site has more than five top-level destinations, a tab bar alone is the wrong tool (see the chapter on choosing a pattern).
The markup
A tab bar is still navigation, so it uses a nav element with a label, a list of links, and no ARIA tab roles. This point is a common source of mistakes. The ARIA tablist and tab roles describe widgets that switch panels inside one page. A tab bar that links to different pages or routes is a set of links, and screen readers should announce it that way.
The tab bar uses aria-current="page" to mark the active link. Screen readers announce it as "current page," so the highlight is not conveyed by color alone.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Home</title>
<style>
body {
margin: 0;
font-family: system-ui, sans-serif;
/* Reserve room so the fixed bar never hides the last content. */
padding-bottom: calc(48px + env(safe-area-inset-bottom));
}
.tab-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
background: #fff;
border-top: 1px solid #ccc;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar a {
flex: 1;
min-height: 48px;
display: flex;
align-items: center;
justify-content: center;
color: #333;
text-decoration: none;
}
.tab-bar a[aria-current="page"] {
font-weight: bold;
color: #0b57d0;
}
.tab-bar a:focus-visible {
outline: 3px solid #0b57d0;
outline-offset: -3px;
}
</style>
</head>
<body>
<main>
<h1>Home</h1>
<p>Page content goes here.</p>
</main>
<nav class="tab-bar" aria-label="Primary">
<a href="/home" aria-current="page">Home</a>
<a href="/search">Search</a>
<a href="/orders">Orders</a>
<a href="/account">Account</a>
</nav>
</body>
</html>Each part of this page has a job.
position: fixedwithleft: 0; right: 0; bottom: 0pins the bar to the bottom edge of the viewport.display: flexon the bar andflex: 1on each link give every tab an equal share of the width. Four tabs on a 360px screen are 90px wide each, which is comfortable.min-height: 48pxsets the touch target height. The width comes from the flex share, so the target is larger than 48px in both directions.aria-label="Primary"distinguishes this landmark from any othernavon the page. Screen reader users can list landmarks and pick the right one.
Safe areas and the viewport tag
Modern phones have rounded corners, notches, and a home indicator, which is the thin bar at the bottom of the screen on iPhones without a home button. In a browser, the page is normally laid out inside the safe area, so the bar does not collide with those features. When a site runs as an installed web app, or when you opt in with viewport-fit=cover, the page extends to the physical edges of the screen. Content at the bottom edge can then sit under the home indicator and be hard to tap.
CSS exposes the unsafe region as env(safe-area-inset-bottom). The value is 0 on devices without an inset, so using it is harmless elsewhere.
Two things must be true for it to have any effect:
- The viewport meta tag must include
viewport-fit=cover. Without it, the browser keeps the page inside the safe area itself and the inset is0. - The bar must use the inset as padding, as in
padding-bottom: env(safe-area-inset-bottom). The link row then stays above the home indicator, while the bar's white background still extends to the physical edge of the screen.
Touch targets and thumb reach
The tab bar inherits the touch-target rules from the earlier chapter. The key numbers are:
| Measure | Guideline |
|---|---|
| Minimum target size | 44 by 44 CSS pixels (WCAG 2.5.5, level AAA) or 24 by 24 (WCAG 2.2 AA minimum) |
| Recommended size | At least 48 by 48 CSS pixels |
| Space between targets | Enough that a thumb does not hit two at once |
| Tab count | 3 to 5 |
The count matters because widths are shared. Six tabs on a 360px screen leave 60px each, and labels such as "Notifications" no longer fit. Five is the practical ceiling for text labels. If you need more destinations, one common solution is to make the last tab a "More" link that opens a page or menu with the rest of the destinations.
Tabs also benefit from an icon above a short label. Icons alone are ambiguous, so keep the text. A tab with an icon and a label looks like this:
<a href="/orders" aria-current="page">
<span class="tab">
<svg aria-hidden="true" focusable="false" width="24" height="24" viewBox="0 0 24 24">
<path d="M4 4h16v16H4z" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>
<span>Orders</span>
</span>
</a>The aria-hidden="true" on the SVG keeps the decorative icon out of the accessibility tree. The visible text becomes the link's accessible name. To stack the icon above the label, make .tab a flex column:
.tab {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
font-size: 0.75rem;
}Showing the active tab
The active state must not rely on color alone. The example above changes weight and color, and many production designs also add a filled icon or an indicator line. Two points apply:
- Style from the attribute (
a[aria-current="page"]), not from a separate.activeclass. This way the visual state and the accessible state cannot drift apart. - In a multi-page site, the server or template sets
aria-currentfor each page. In a single-page app, your router must move the attribute on every navigation. A common bug is that the highlight updates butaria-currentstays on the first tab.
Do not use aria-current on more than one link at a time. It marks one location.
Badges
A badge is a small count on a tab, such as "3" on Orders. A screen reader reads only what is in the text, so a bare number is not enough. Put a short, hidden-from-sight description in the link:
<a href="/orders">
Orders
<span class="badge" aria-hidden="true">3</span>
<span class="visually-hidden">, 3 new</span>
</a>.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}The visible badge is hidden from assistive technology and the visually hidden text is read instead. The link is announced as "Orders, 3 new."
Common problems
The bar covers content
Because the bar is fixed, it floats above the page. Without bottom padding on the body (or the main scroll container), the last paragraph or button sits underneath it and cannot be reached. The fix is the padding-bottom in the example. Use the same height as the bar, plus the safe-area inset. If you change the bar height, change the padding too. A shared CSS custom property keeps them in sync:
:root {
--tab-bar-height: 48px;
}
body {
padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
}
.tab-bar a {
min-height: var(--tab-bar-height);
}The on-screen keyboard pushes the bar up
On some mobile browsers, opening the on-screen keyboard shrinks the visual viewport, and a fixed bar can end up floating above the keyboard and covering the input the user is typing in. Common mitigations are to hide the bar while a text field has focus, or to avoid a fixed bar on pages dominated by forms. Test this on a real device, because desktop emulators do not reproduce it.
Browser toolbars move
On iOS Safari and Chrome for Android, the browser's own address bar and toolbar collapse as the user scrolls. A bar fixed to the bottom may jump slightly, or sit close to the browser's own controls and invite accidental taps. Keep enough padding around the tabs and avoid putting small targets next to the screen edge.
Wide screens
A bottom bar on a 1400px-wide desktop window is awkward: tabs stretch across the full width and sit far from the content. Chapter 10 covers how to swap patterns by breakpoint. Until then, a simple stopgap is to hide the bar above a width and provide another navigation for large screens.
Focus is hidden
Keyboard users tab through the links in order, and the focused link must be clearly visible. The :focus-visible rule in the example draws an inset outline. An outline that extends outside the bar can be clipped at the screen edge, which is why the example uses a negative outline-offset.
When a tab bar is the wrong choice
Choose something else if any of these apply:
- You have more than five top-level destinations of similar importance.
- Your destinations are not peers. Tabs imply equal, parallel sections, such as Home, Search, and Account. They do not suit a hierarchy such as Products, then Category, then Item.
- Your pages are mostly long forms or checkout flows, where the keyboard is often open and the bar adds clutter.
- Your site is content-heavy, such as articles, and vertical space is more valuable than shortcuts.
Exercise
A tab bar uses position: fixed; bottom: 0 and the site's <meta name="viewport"> is width=device-width, initial-scale=1. The developer adds padding-bottom: env(safe-area-inset-bottom) to the bar and sees no change on a phone with a home indicator. What is the likely cause, and what is the fix?
Show answer
Without viewport-fit=cover in the viewport meta tag, the browser keeps the page inside the safe area, so env(safe-area-inset-bottom) evaluates to 0 and the padding has no effect. Add viewport-fit=cover to the viewport tag (width=device-width, initial-scale=1, viewport-fit=cover). The page then extends to the screen edges and the inset reports the real value.
Exercise
Why should a tab bar that links to separate pages use aria-current="page" on the active link instead of role="tablist" and role="tab" with aria-selected?
Show answer
The ARIA tab roles describe a widget that switches between panels within one page, with specific keyboard behavior such as arrow keys moving between tabs. A bar of links navigates to other pages, so it should be a nav containing links. aria-current="page" tells screen readers which link points to the current location without promising tab-widget behavior the page does not implement.
Exercise
The last item on a long page cannot be tapped because the fixed tab bar covers it. Name the cause and write the CSS fix for a 56px bar.
Show answer
A fixed element is removed from normal flow, so the page does not reserve space for it. Add bottom padding equal to the bar height plus the safe-area inset to the body or main scroll container: body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }.