Tabs is a component that makes navigating between sections of related content possible, displaying one section at a time.
Table of contents
How to use Tabs
Use Tabs if the content can be separated into sections that make sense as standalone pieces of information.
Be aware that the users will not see all the content at the same time. Make sure the first section is the most relevant one.
Code examples
<Tabs role="tablist">
<Tab id="first" href="https://contentful.com" isSelected>
First
</Tab>
<Tab id="second" href="https://contentful.com">
Second
</Tab>
<Tab id="third" href="https://contentful.com">
Third
</Tab>
</Tabs>
with vertical divider
<Tabs role="tablist" variant="vertical-divider">
<Tab id="first" href="https://contentful.com" isSelected>
First
</Tab>
<Tab id="second" href="https://contentful.com">
Second
</Tab>
<Tab id="third" href="https://contentful.com">
Third
</Tab>
</Tabs>
as navigation
<Tabs role="navigation">
<Tab id="first" href="https://contentful.com" isSelected>
First
</Tab>
<Tab id="second" href="https://contentful.com">
Second
</Tab>
<Tab id="third" href="https://contentful.com">
Third
</Tab>
</Tabs>
used with TabPanel
() => {
const [selected, setSelected] = React.useState('first');
return (
<>
<Tabs role="tablist">
<Tab id="first" isSelected={selected === 'first'}>
First
</Tab>
<Tab id="second" isSelected={selected === 'second'}>
Second
</Tab>
</Tabs>
{selected === 'first' && (
<TabPanel id="first">Content for the first tab</TabPanel>
)}
{selected === 'second' && (
<TabPanel id="second">Content for the second tab</TabPanel>
)}
</>
);
};
Content recommendations
- every Tab should have concise copy
- all content within a Tab should be related to it's label
- to ensure an optimal cognitive load for users, do not use more than six (6) Tabs at any given time
Props
import { Props } from '@contentful/f36-docs-utils';
Tabs
Tab
TabPanel