App navigation
Tabs
Onglets
Demo
Loading demo…
A row of labels that shows one content panel at a time. Tabs group several views of the same subject in one place, without leaving the page.
Story
Did you know
The metaphor comes from the tabbed dividers in paper binders. The first tabbed browsers appeared in the late 90s, but it took Opera and then Firefox to make tabs the norm, and IE7 in 2006 for Microsoft to follow.
Timeline
- paperTabbed dividers in office binders.
- 1980sTabbed dialog boxes appear in graphical interfaces.
- 2000sOpera, then Firefox, make tabbed browsing popular.
- 2006Internet Explorer 7 finally adds tabs.
Vocabulary
Names
- FR
- Onglets, barre d'onglets, navigation par onglets
- EN
- Tabs, tab bar, tablist, tab strip, tabbed interface, segmented control
Common uses
- Switching between views of one object (Overview / Code / Settings)
- Product pages: Description, Reviews, Shipping
- Main navigation in a mobile app (bottom tab bar)
- Code samples in several languages
Often paired with
The components it usually sits with, by page type, in reading order.
Product page
See the mock-upCode
<div role="tablist" aria-label="Project">
<button role="tab" id="tab-0" aria-controls="panel-0" aria-selected="true">Overview</button>
<button role="tab" id="tab-1" aria-controls="panel-1" aria-selected="false" tabindex="-1">Code</button>
<button role="tab" id="tab-2" aria-controls="panel-2" aria-selected="false" tabindex="-1">Settings</button>
</div>
<div role="tabpanel" id="panel-0" aria-labelledby="tab-0" tabindex="0">Overview panel</div>
<div role="tabpanel" id="panel-1" aria-labelledby="tab-1" tabindex="0" hidden>Code panel</div>
<div role="tabpanel" id="panel-2" aria-labelledby="tab-2" tabindex="0" hidden>Settings panel</div>
<script>
const tabs = [...document.querySelectorAll('[role="tab"]')]
function select(tab) {
for (const t of tabs) {
const on = t === tab
t.setAttribute('aria-selected', on)
t.tabIndex = on ? 0 : -1
document.getElementById(t.getAttribute('aria-controls')).hidden = !on
}
tab.focus()
}
tabs.forEach((tab, i) => {
tab.addEventListener('click', () => select(tab))
tab.addEventListener('keydown', (e) => {
const n = tabs.length
const target = { ArrowLeft: i - 1 + n, ArrowRight: i + 1, Home: 0, End: n - 1 }[e.key]
if (target === undefined) return
e.preventDefault()
select(tabs[target % n])
})
})
</script>Good to know
- If each tab has its own URL, they are navigation links (
<nav>+aria-current="page"), not ARIA tabs. - Hide inactive panels with
hiddeninstead of unmounting them: a half-filled form or a scroll position survives a tab switch. - With
hidden="until-found", Ctrl+F finds text in hidden panels; thebeforematchevent tells you which tab to open. Supported in Chrome and Edge, not everywhere yet. - Too many tabs for the width? Let the bar scroll sideways (
overflow-x: auto+scroll-snap) instead of wrapping it onto two rows.
Accessibility
Must have
- There is no native HTML element: you need the
role="tablist"/tab/tabpaneltrio, witharia-selected,aria-controlsandaria-labelledby. - Keyboard: Tab enters the bar on the active tab, Left/Right arrows switch tabs, Home/End jump to the first and last. Only the active tab has
tabindex="0"(roving tabindex).
Often forgotten
- Give the panel
tabindex="0"when it holds nothing focusable, so Tab can reach it. - Vertical tabs: add
aria-orientation="vertical"and handle the Up/Down arrows. - The active tab must not rely on colour alone: underline, weight or background (WCAG 1.4.1).
Nice to have
- If a panel is slow to load, switch to manual activation: arrows move focus, Enter or Space selects.
- Closable tabs: the Delete key closes the focused tab.