Examples
Code
React
See Storybook "Tabs" page for React documentation.
Style customization
The following CSS variables can be overridden to customize Tab components:
Guidance
When to use
- If you have sub-sections of a page, and there's the need to only show one sub-section at a time.
When to consider alternatives
- If you have more than four tabs. Consider using a different pattern if your content requires being split into more than four panels.
- If the panel contents can be displayed at once. This will improve the scanability of your page's content and it's more likely the user will be able to find what they're looking for. Typography, including clear section headers, should be enough to allow the user to navigate the page.
Usage
- Avoid overflowing tabs to new lines. If the tabs can't fit on one row on small screens, consider using utility classes to apply additional responsive styles or use a different pattern.
- Tab labels should be descriptive of their content and set the user's expectations.
- Tab labels should be short — aim for no more than two words.
Accessibility
- Use an anchor link (
a
) to create the tabs. This allows you to link directly to a tab, and allows you to progressively enhance the page, retaining default browser behavior like opening links in a new window. Note: You'll need to implement the logic for selecting the correct tab based on the current URL. - Ensure the HTML markup includes the proper ARIA attributes:
- For tabs:
role
,aria-selected
,aria-controls
- For the tabs list parent:
role
,aria-label
- For a tab panel:
role
,aria-labelledby
- For tabs:
Related patterns
Learn more
Component maturity
This component meets 89% of our maturity criteria.
Incomplete criteria
- Incomplete
Responsive:Â Component designed to work in all responsive breakpoints.
What does this mean?
Each component is tested against the following items to gauge the component's maturity. When using incomplete components, consider the unmet criteria as applied to your product.
For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.
- Complete
Color:Â Meets AA color contrast standards for accessibility and color blindness.
- Complete
Forced Colors Mode (FCM):Â While using FCM the components text is legible and improves readability.
- Complete
WCAG 2.1 Level AA Conformance:Â All Axe checks for WCAG AA compliance have passed.
- Complete
Screen readers:Â VoiceOver, NVDA, and JAWS screen readers provide concise communication and interaction.
- Complete
Keyboard navigation:Â Component is fully navigable with a keyboard.
Accessibility
- Complete
Storybook:Â Component has stories to cover all defined props.
- Incomplete
Responsive:Â Component designed to work in all responsive breakpoints.
- Not applicable
Spanish translations:Â Includes Spanish translations for default text content.
Code
- Complete
Code:Â Tokens implemented in code.
- Complete
Design:Â Tokens implemented in the Sketch.