Tab groups organize related content into a single container that displays one panel at a time, with tabs for
switching between them.
GeneralCustomAdvancedDisabledThis is the general tab panel.This is the custom tab panel.This is the advanced tab panel.This is a disabled tab panel.
<cs-tab-group><cs-tabpanel="general">General</cs-tab><cs-tabpanel="custom">Custom</cs-tab><cs-tabpanel="advanced">Advanced</cs-tab><cs-tabpanel="disabled"disabled>Disabled</cs-tab><cs-tab-panelname="general"active>This is the general tab panel.</cs-tab-panel><cs-tab-panelname="custom">This is the custom tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel><cs-tab-panelname="disabled">This is a disabled tab panel.</cs-tab-panel></cs-tab-group>
Tab groups make use of tabs and tab panels. Each panel should have a name that’s unique within the tab group, and tabs should have a panel attribute that points to the respective panel’s name.
Examples
Active Tab
To make a tab active, set the active attribute to the name of the appropriate panel.
GeneralCustomAdvancedThis is the general tab panel.This is the custom tab panel.This is the advanced tab panel.
<cs-tab-groupactive="advanced"><cs-tabpanel="general">General</cs-tab><cs-tabpanel="custom">Custom</cs-tab><cs-tabpanel="advanced">Advanced</cs-tab><cs-tab-panelname="general">This is the general tab panel.</cs-tab-panel><cs-tab-panelname="custom">This is the custom tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel></cs-tab-group>
Placement
Set the placement attribute to move the tabs to a different edge of the panels.
Placement
Tabs appear
topdefault
Above the panels, horizontally
bottom
Below the panels, horizontally
start
Before the panels, stacked vertically
end
After the panels, stacked vertically
GeneralCustomAdvancedDisabledThis is the general tab panel.This is the custom tab panel.This is the advanced tab panel.This is a disabled tab panel.
<cs-tab-groupplacement="bottom"><cs-tabpanel="general">General</cs-tab><cs-tabpanel="custom">Custom</cs-tab><cs-tabpanel="advanced">Advanced</cs-tab><cs-tabpanel="disabled"disabled>Disabled</cs-tab><cs-tab-panelname="general"active>This is the general tab panel.</cs-tab-panel><cs-tab-panelname="custom">This is the custom tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel><cs-tab-panelname="disabled">This is a disabled tab panel.</cs-tab-panel></cs-tab-group>
GeneralCustomAdvancedDisabledThis is the general tab panel.This is the custom tab panel.This is the advanced tab panel.This is a disabled tab panel.
<cs-tab-groupplacement="start"><cs-tabpanel="general">General</cs-tab><cs-tabpanel="custom">Custom</cs-tab><cs-tabpanel="advanced">Advanced</cs-tab><cs-tabpanel="disabled"disabled>Disabled</cs-tab><cs-tab-panelname="general"active>This is the general tab panel.</cs-tab-panel><cs-tab-panelname="custom">This is the custom tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel><cs-tab-panelname="disabled">This is a disabled tab panel.</cs-tab-panel></cs-tab-group>
Closable Tabs
You can make a tab closable by adding a close button next to the tab and inside the nav slot. You can position the button to your liking with CSS and handle close/restore behaviors by removing/appending the tab as desired. Note the use of tabindex="-1", which prevents the close button from interfering with the tab order. The close button is still recognizable to the virtual cursor in screen readers.
GeneralClosableAdvancedThis is the general tab panel.This is the closable tab panel.This is the advanced tab panel. Restore tab
<cs-tab-groupclass="tabs-closable"><cs-tabpanel="general">General</cs-tab><cs-tabpanel="closable">Closable</cs-tab><cs-buttonslot="nav"tabindex="-1"appearance="plain"size="s"><cs-iconname="close"label="Close the closable tab"></cs-icon></cs-button><cs-tabpanel="advanced">Advanced</cs-tab><cs-tab-panelname="general">This is the general tab panel.</cs-tab-panel><cs-tab-panelname="closable">This is the closable tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel></cs-tab-group><br/><cs-buttondisabled>Restore tab</cs-button><style>.tabs-closable cs-button{position: relative;left: -1.5em;top: 0.675em;}</style><script>const tabGroup = document.querySelector('.tabs-closable');const generalTab = tabGroup.querySelectorAll('cs-tab')[0];const closableTab = tabGroup.querySelectorAll('cs-tab')[1];const closeButton = tabGroup.querySelector('cs-button');const restoreButton = tabGroup.nextElementSibling.nextElementSibling;// Remove the tab when the close button is clicked
closeButton.addEventListener('click',()=>{
closableTab.remove();
closeButton.remove();
restoreButton.disabled =false;});// Restore the tab
restoreButton.addEventListener('click',()=>{
restoreButton.disabled =true;
generalTab.insertAdjacentElement('afterend', closeButton);
generalTab.insertAdjacentElement('afterend', closableTab);});</script>
Scrolling Tabs
When there are more tabs than horizontal space allows, the nav will be scrollable.
When focused, keyboard users can press Left or Right to select the desired tab. By default, the corresponding tab panel will be shown immediately (automatic activation). You can change this behavior by setting activation="manual" which will require the user to press Space or Enter before showing the tab panel (manual activation).
GeneralCustomAdvancedDisabledThis is the general tab panel.This is the custom tab panel.This is the advanced tab panel.This is a disabled tab panel.
<cs-tab-groupactivation="manual"><cs-tabpanel="general">General</cs-tab><cs-tabpanel="custom">Custom</cs-tab><cs-tabpanel="advanced">Advanced</cs-tab><cs-tabpanel="disabled"disabled>Disabled</cs-tab><cs-tab-panelname="general">This is the general tab panel.</cs-tab-panel><cs-tab-panelname="custom">This is the custom tab panel.</cs-tab-panel><cs-tab-panelname="advanced">This is the advanced tab panel.</cs-tab-panel><cs-tab-panelname="disabled">This is a disabled tab panel.</cs-tab-panel></cs-tab-group>
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import
needed. To cherry-pick this component, use one of the following snippets.
When set to auto, navigating tabs with the arrow keys will instantly show the corresponding tab panel. When set to manual, the tab will receive focus but will not show until the user presses spacebar or enter.
'auto' | 'manual'
'auto'
—
active
active
Sets the active tab.
string
''
Yes
defaultSlot
—
Default slot for <cs-tab-panel> children (inside the body part container).
HTMLSlotElement
—
—
placement
placement
The placement of the tabs.
'top' | 'bottom' | 'start' | 'end'
'top'
—
withoutScrollControls
without-scroll-controls
Disables the scroll arrows that appear when tabs overflow.
During SSR, <cs-tab-group> can't access its children to determine which tab is active. To render the correct panel, manually set the active attribute on the matching <cs-tab> and <cs-tab-panel>.