good tabs UI (user interface) design comes down to five decisions. Use tabs only for related, parallel content that people don’t need to compare side by side. Keep labels to one or two words, and make the active tab obvious with more than colour alone.
Wire the component so arrow keys move between tabs. On small screens, let the row scroll sideways, or swap it for a select menu or an accordion. The rest of this guide shows how, with HTML, CSS and accessibility markup you can copy.
Tabs look like the simplest pattern in an interface. Done well, they cut cognitive load, the mental effort it takes to find something, because people only see one group of related content at a time. In practice, they’re easy to get subtly wrong.
A tab bar can hide content people needed to see together. It can show an active state nobody can spot, or break on a phone. Each section below covers one of those decisions, from placement to keyboard support.
How a tabs component works
A tabs component switches between related views of content at the same level, without leaving the page. Only one panel shows at a time. The others stay in the page, hidden, so switching feels instant.
The anatomy is the same in almost every design system:
- Container: the frame that holds the tab group together and sets its spacing and alignment.
- Tab item: each clickable segment. It carries a label, sometimes an icon or a badge, and its interactive states.
- Label: the text that tells people what they’ll see before they click.
- Badge (optional): a small count or status marker, such as the number of new messages.
- Active indicator: the underline, highlight or filled background that marks the selected tab.
- Content panel: the area where the selected tab’s content appears. Its position never moves.
HTML has no native tabs element. You build tabs from buttons and containers. Then you add roles from ARIA (Accessible Rich Internet Applications), a web standard that tells screen readers what a custom widget is.
The three roles are tablist, tab and tabpanel. The ARIA Authoring Practices Guide (APG), published by the World Wide Web Consortium, describes how they should behave, and it’s the reference we follow below.
It also helps to separate two kinds of tabs. In-page tabs swap panels inside one page, like Description, Reviews and Specs on a product page.
Navigation tabs load a new page or route on each click, like a mobile bottom bar. They look alike, but navigation tabs are a different navigation pattern: they’re really links, and they shouldn’t use the tab role. Primer, GitHub’s design system, keeps them as two separate components for this reason.

When tabs beat accordions (and when to avoid using tabs)
Tabs work best when the content splits into mutually exclusive groups of equal importance. People should be able to jump between them often, and they should rarely need two of them on screen at once. Settings panels, dashboards and product details fit that description well.
Accordions stack sections vertically and let people open several at once. That makes them better for long text on narrow screens, and for content people scan from top to bottom, such as an FAQ. Tabs keep every label visible in one row, so they win when people switch back and forth.
Each accordion section is a disclosure widget: one button that shows or hides one block. The HTML standard is explicit that tab widgets are not disclosure widgets. A group of <details> elements sharing a name is a valid exclusive accordion, not a substitute for tabs.
| Situation | Use | Avoid |
|---|---|---|
| 3 to 6 parallel views people switch between often (account settings, product details) | Horizontal tabs | A long single page with an anchor menu |
| Many sections or long labels (documentation, admin areas) | Vertical tabs or a sidebar | A horizontal row squeezed until labels shrink |
| Content read in sequence, or several sections needed at once | Accordion or plain headings | Tabs, which hide the context people need |
| Data people must compare (pricing plans, specs) | A comparison table | One tab per option |
| Two or three filters of the same list (Monthly / Yearly) | Segmented control | A full tab bar with panels |
| Steps that must happen in order (checkout, onboarding) | A stepper or wizard | Tabs, which suggest any order is fine |
A segmented control is a lightweight cousin of tabs, with a simpler interaction pattern. It behaves like a set of toggle buttons that filter one view. Revolut’s help centre, for example, uses one to switch between Personal and Business topics.
Material Design adds two warnings that are easy to forget. First, don’t use tabs for carousels or for paging through content, because that’s viewing, not navigating between groups. Second, don’t pair tabs with content that already responds to swipes, such as a pannable map. On touch screens the swipe would fight the tab switch.
The last case is the small site. If a page has two short blocks of text, tabs add a click and hide half the content. Two headings on a single page do the job better.
Horizontal vs vertical tabs: choosing tab placement
Horizontal tabs are the default, and for good reason. They sit directly above their panel, people scan them left to right, and they suit desktop and tablet widths. They work best when the number of tabs stays around three to six categories. Blazeup, a time-tracking tool, puts Overview, Timesheet and Timeoff in a horizontal row, so people switch views without leaving the screen.
Vertical tabs sit in a column on the left. They leave room for longer, more descriptive labels and for many categories. That’s why documentation sites and settings pages often use them: the list stays visible while the content area changes. Spectrum (Adobe’s design system) and Carbon both document a vertical option.
A few placement rules apply to both orientations:
- Keep the tabs adjacent to their panel, so the link between label and content is obvious.
- Present tabs as a single row (or a single column), never as a grid of wrapped rows.
- Avoid nested tabs, meaning a second set of tabs inside a tab panel. Two levels of hidden content are hard to follow.
- Put the most-used tab first, because it’s also the one shown by default.
Tabs at the bottom of a phone screen are a different pattern. A bottom bar in an app is top-level navigation between unrelated destinations, and Material Design limits it to a handful of items. Moving an in-page tab bar to the bottom for thumb reach confuses people who expect it above the content. If one-handed use matters, keep tabs at the top and make them sticky instead.
In code, orientation is a single attribute: add aria-orientation="vertical" to the tab list. It tells assistive technology which way the list runs, and your script should use the Up and Down arrows instead of Left and Right.

Tab labels: length, icons and badges
A tab label has one job: tell people what’s behind the tab before they click. People should understand each tab at a glance, and short, specific nouns do that best, such as “Reviews”, “Shipping” or “Billing”. A practical starting point is one or two words. Longer labels crowd the row quickly, and on mobile they force scrolling sooner.
Labels should also be meaningful distinctions. “Overview”, “Details” and “More info” overlap, so people can’t predict where a fact lives. If you struggle to name a tab without overlap, the content probably needs a different split.
When a label is too long for its tab, Material Design’s guidance is clear: wrap it to a second line, and only then truncate. Don’t shrink the font of one label to make it fit, because uneven type sizes look like a bug. Truncating too early hurts comprehension, since people can’t read the end of the label.
Icons help recognition in dense interfaces and on mobile, but an icon on its own is often a guessing game. Pair icons with text, and keep the set consistent: all tabs with icons, or none.
Badges work well for counts and alerts, such as “Messages 3”. Keep them small, so the label stays readable.
One label decides more than the others: the default tab. It should be the content most people came for. On a product page, that’s usually the description, not the returns policy.
Styling the active, hover, focus and disabled states
A tab has more states than people expect. The APG pattern and the main design systems cover these:
- Default: one tab selected, the others not.
- Hover: a pointer-only hint, such as a light background.
- Focus: a visible ring when someone moves through the tabs with the keyboard.
- Active (selected): the persistent state of the current tab, plus the brief pressed state.
- Disabled: a tab people can’t open yet. Use it sparingly.
In our view, the selected state is where most designs fail. When the active tab barely differs from the others, people have to hunt for it. Make the difference strong on at least two channels: an underline or filled background, plus a change in text colour or weight. The Web Content Accessibility Guidelines (WCAG) cover this in success criterion 1.4.1, Use of Color, which says colour must not be the only way to convey information.
Contrast has a measurable floor too. WCAG 1.4.11 (Non-text Contrast) sits at level AA (the middle conformance level). It asks for at least 3:1 contrast for the visual parts of UI components needed to identify them and their state. A tab indicator in pale grey on white fails that test.
Label text follows WCAG 1.4.3, which sets 4.5:1 for normal-size text, so faded labels on inactive tabs still need enough contrast.
For focus, WCAG 2.4.7 (Focus Visible, level AA) requires a visible focus indicator. Don’t remove the outline without replacing it. The :focus-visible selector shows the ring for keyboard users without showing it on every mouse click.
WCAG 2.2 also added 2.4.11 (Focus Not Obscured, level AA): a sticky header must not hide the focused tab entirely. Level AAA (criterion 2.4.12) goes further and forbids hiding any part of it.
Disabled tabs deserve a second thought. A greyed-out tab with no explanation frustrates people. Often it’s better to show the tab and explain inside the panel why its content isn’t available yet.

Keyboard navigation and ARIA markup
The APG tabs pattern defines the keyboard contract that screen reader and keyboard users expect:
- Tab: moves focus into the tab list, onto the active tab. Pressing Tab again leaves the list and goes to the panel.
- Left and Right arrows: move focus to the previous or next tab, wrapping from the last tab to the first tab.
- Home and End (optional): jump to the first or last tab.
- Space or Enter: activate the focused tab if it wasn’t activated automatically.
- Up and Down arrows: replace Left and Right in a vertical tab list.
This relies on a technique called a roving tabindex. Only the selected tab has tabindex="0", so it’s the only one reachable with the Tab key. The others get tabindex="-1", and people reach them with the arrows. A horizontal tab list ignores Up and Down, so those keys still scroll the page.
You also choose between automatic and manual activation. With automatic activation, the panel changes as soon as a tab gets focus. The APG recommends it when panels display without noticeable delay. If a panel has to load data first, use manual activation, where people move with the arrows and press Enter or Space to open.
Here’s the markup for a three-tab product block:
<div class="tabs">
<div role="tablist" aria-label="Product details">
<button role="tab" id="tab-desc" aria-selected="true"
aria-controls="panel-desc">Description</button>
<button role="tab" id="tab-specs" aria-selected="false"
aria-controls="panel-specs" tabindex="-1">Specs</button>
<button role="tab" id="tab-reviews" aria-selected="false"
aria-controls="panel-reviews" tabindex="-1">Reviews</button>
</div>
<div role="tabpanel" id="panel-desc" aria-labelledby="tab-desc" tabindex="0">…</div>
<div role="tabpanel" id="panel-specs" aria-labelledby="tab-specs" tabindex="0" hidden>…</div>
<div role="tabpanel" id="panel-reviews" aria-labelledby="tab-reviews" tabindex="0" hidden>…</div>
</div>
For readability, the example hard-codes hidden on panels two and three. On a live site, have the script set it at startup instead, so the content stays visible if JavaScript fails.
The tabindex="0" on each panel follows the APG advice for panels that don’t start with a focusable element. It lets keyboard users reach the panel content directly. The script below handles clicks, arrows, Home and End with automatic activation:
document.querySelectorAll('[role="tablist"]').forEach((list) => {
const tabs = [...list.querySelectorAll('[role="tab"]')];
const select = (tab) => {
tabs.forEach((t) => {
const on = t === tab;
t.setAttribute('aria-selected', on);
t.tabIndex = on ? 0 : -1;
document.getElementById(t.getAttribute('aria-controls')).hidden = !on;
});
tab.focus();
};
list.addEventListener('click', (e) => {
const tab = e.target.closest('[role="tab"]');
if (tab) select(tab);
});
list.addEventListener('keydown', (e) => {
const i = tabs.indexOf(document.activeElement);
const vertical = list.getAttribute('aria-orientation') === 'vertical';
const next = vertical ? 'ArrowDown' : 'ArrowRight';
const prev = vertical ? 'ArrowUp' : 'ArrowLeft';
let j = null;
if (e.key === next) j = (i + 1) % tabs.length;
if (e.key === prev) j = (i - 1 + tabs.length) % tabs.length;
if (e.key === 'Home') j = 0;
if (e.key === 'End') j = tabs.length - 1;
if (j !== null) { e.preventDefault(); select(tabs[j]); }
});
});
WCAG 2.1.1 (Keyboard, level A) requires all functionality to work from a keyboard, so this isn’t optional polish.
CSS for a responsive tab component
The CSS styles the states through the same ARIA attributes the script changes. That keeps one source of truth: if aria-selected says a tab is active, it looks active.
.tabs [role="tablist"] {
display: flex;
gap: 4px;
border-bottom: 1px solid #8a8a8a;
overflow-x: auto;
scroll-snap-type: x proximity;
}
.tabs [role="tab"] {
min-height: 48px;
padding: 0 16px;
border: 0;
border-bottom: 3px solid transparent;
background: none;
color: #4a4a4a;
font: inherit;
white-space: nowrap;
scroll-snap-align: start;
cursor: pointer;
}
.tabs [role="tab"]:hover { background: #f2f2f2; }
.tabs [role="tab"][aria-selected="true"] {
color: #111;
border-bottom-color: #0b57d0;
font-weight: 600;
}
.tabs [role="tab"]:focus-visible {
outline: 2px solid #0b57d0;
outline-offset: -2px;
}
@media (prefers-reduced-motion: no-preference) {
.tabs [role="tab"] { transition: color .15s, border-color .15s; }
}
/* Vertical variant */
.tabs--vertical { display: grid; grid-template-columns: minmax(12rem, auto) 1fr; }
.tabs--vertical [role="tablist"] {
flex-direction: column;
border-bottom: 0;
border-right: 1px solid #8a8a8a;
}
@media (max-width: 40em) {
.tabs--vertical { grid-template-columns: 1fr; }
.tabs--vertical [role="tablist"] {
flex-direction: row;
border-right: 0;
border-bottom: 1px solid #8a8a8a;
}
}
The 48px minimum height matches the tab height in the Material Design 1 specs, and it gives a comfortable touch target. The prefers-reduced-motion media query keeps transitions only for people who haven’t asked their system to reduce motion.
The vertical variant falls back to a horizontal row below 40em, roughly 640px, which is a common breakpoint rather than a rule. If your script switches orientation too, update aria-orientation at the same breakpoint.
Many galleries show “pure CSS” tabs built with hidden radio buttons and the :checked selector. They’re lightweight and need no JavaScript, but they don’t expose the tab roles, so screen readers announce radio buttons instead of tabs, and the APG keyboard behaviour isn’t guaranteed. Use them for demos, not for production content.
Animation deserves restraint. A sliding underline helps people follow the switch. Heavy fades and slides between large panels can make a page feel slow on modest devices. Animate the indicator, keep panel changes instant or short, and keep the panel content in the HTML rather than in several animated copies.

Tabs on mobile: scrollable row, select menu or accordion
Mobile screens break tabs in a predictable way: the row runs out of width. A tab bar has to adapt to different screen sizes, not just shrink.
Material Design separates fixed tabs from scrollable tabs. Fixed tabs show every tab at once with equal widths, so they suit a small, stable set. Scrollable tabs show a subset and let people reveal the rest by swiping the row, so they suit many or variable tabs. YouTube’s category chips are a familiar scrollable example.
Once the row overflows, you have three options:
- Scrollable row: the code above already does this with
overflow-x: auto. Let the last visible tab show partly, so people see there’s more. - Overflow menu: keep the first tabs visible and move the rest into a “More” dropdown menu. GitHub does this on repository pages when the window narrows.
- Select menu or accordion: below a breakpoint, replace the tab list with a native
<select>that drives the same panels, or turn each tab into an accordion header.
Our preference for most websites is the scrollable row up to about six tabs, then a select menu. The select is accessible by default and familiar to everyone.
Scrollbars are a common sore point. A visible horizontal scrollbar under the tab row looks clumsy on desktops that show scrollbars, yet hiding it entirely removes the cue that the row scrolls. A middle ground is a thin, styled scrollbar with scrollbar-width: thin, or a soft fade at the row’s edge.
Touch targets need room. WCAG 2.5.8 (Target Size Minimum, level AA in WCAG 2.2) sets 24 by 24 CSS pixels as the floor. Apple’s Human Interface Guidelines recommend at least 44 by 44 points, and the 48px height above clears both.
Finally, should a long page on mobile use tabs at all? If people read every section, a single scrolling page with clear headings is usually better. Tabs pay off when people want one section and ignore the rest.
Real examples from design systems
Studying how established design systems ship tabs saves a lot of trial and error. Here’s what a few of them do, and what each teaches:
- Carbon: line tabs, contained tabs and vertical tabs, with documented hover, focus and disabled states. A good model for enterprise dashboards.
- Material Web (Google): primary and secondary tabs, so a page can show a main set of views and a less prominent set for finer splits.
- The UK government’s design system (GOV.UK Design System): builds tabs from links to page sections. Without JavaScript, the content appears stacked under a contents list, so visitors lose nothing if the script fails.
- Primer (GitHub): separates in-page tab panels from link-based navigation, which avoids misusing the tab role.
- Spectrum (Adobe): offers horizontal and vertical directions and a compact density for tight layouts.
- U.S. Web Design System (USWDS): ships no tabs component at all, and offers side and in-page navigation instead.
That last example is worth a moment. In our view, that’s a sensible choice: for content-heavy public pages, visible headings often beat hidden panels. For a web design agency, the GOV.UK approach is the one to copy on client sites: progressive enhancement, so the page still works without the script. More at https://uiterms.com.

Common tab design pitfalls
People can’t tell which tab is open. The cause is an indicator that relies on a faint colour shift. Add an underline or filled background with at least 3:1 contrast, plus a heavier label.
Neighbouring tabs jump when someone selects a tab. The bold label is wider than the regular one, so the row reflows. Reserve the bold width: add a hidden pseudo-element with the same text in bold, or use a variable font with a stable width.
Keyboard users get stuck pressing Tab through every tab. Every tab has tabindex="0". Apply the roving tabindex shown above, so arrows move between tabs and Tab moves to the panel.
A shared link opens the wrong tab. The selected tab lives only in memory. Write the tab to the URL hash, for example #reviews, and read it on load, so links and the back button work.
Tabbed content is missing for some visitors. The panel loads only after a click, and fails when the script errors. Render all panel content in the HTML, and let the script add the hidden attribute when it starts. Visitors without JavaScript then see every panel stacked, as on GOV.UK, and search engines still get the text.
How to measure whether your tabs work
Tabs are a bet that people want one section at a time. You can check that bet, and the wider user experience, with data you already have. Usability problems with tabs usually show up in three places: ignored tabs, constant switching and keyboard dead ends.
- Tab click events: send an event to your analytics tool each time someone selects a tab. If almost nobody opens the third tab, its content may belong elsewhere.
- Back-and-forth switching: repeated switching between two tabs in one session suggests people are comparing. That content probably needs a table.
- Accessibility checks: run an automated checker such as axe or Lighthouse, then test by hand with the keyboard and a screen reader. Automated tools can’t judge whether arrow keys behave as expected.
- Five-second test: show the page to someone briefly and ask which tab is open. If they hesitate, strengthen the active state.
Run these checks at launch, then again after any redesign of the component.
Tabs UI design checklist
- The content is parallel, related and rarely compared side by side.
- There are about three to six tabs, or the design scrolls or collapses past that.
- Labels are one or two specific words, with no overlap.
- The most-used content is the default tab.
- The active state uses more than colour and reaches 3:1 contrast.
- Focus is visible and never hidden behind a sticky header.
- Markup uses
tablist,tab,tabpanel,aria-selectedandaria-controls. - Arrow keys, Home and End work; Tab leaves the list.
- Vertical lists set
aria-orientation="vertical". - Touch targets are at least 24px, ideally 44 to 48px.
- On mobile, the row scrolls or becomes a select menu or accordion.
- Panel content is in the HTML, and the page still works without JavaScript.
- The URL hash shows the selected tab.
- Motion respects
prefers-reduced-motion.
FAQ
Should tab labels be in all caps?
Material Design 1 specified all caps. We prefer sentence case: it takes less width than capitals, and to our eye it reads more naturally. Whichever you pick, apply it to every tab.
Can I put a form inside a tab?
Yes, as long as the whole form lives in one panel. Splitting one form across several tabs hides required fields and errors. If the form is long, use a stepper instead.
Should every tab panel have the same height?
Not necessarily, but big height changes make the page jump when people switch, and content below the tabs moves. For panels of similar length, a minimum height on the panel area keeps things steady. For very uneven panels, let the height follow the content and keep the tab row at the top of the panel area.
What’s the difference between tabs and a segmented control?
Tabs switch between distinct panels of content. A segmented control filters or changes the mode of one view, like Map and List on a store locator. If the content below keeps the same layout, a segmented control is usually the better fit.
Can tabs open in a new page instead of a panel?
They can, but then they’re navigation, not tabs. Build them as a list of links in a nav element and mark the current one with aria-current="page". Don’t give them the tab role.
The quickest win is to audit one existing tab component this week. Check its labels, active contrast and keyboard behaviour against the checklist, and fix the first item that fails. Good tabs disappear into the page: people find what they need and never think about the interface.
Building or redesigning a site? Browse more of our web design guides for components that look sharp and work for everyone.
