Tabs
A component for toggling between related panels on the same page.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Tabs } from '@base-ui-components/react/tabs';
<Tabs.Root>
<Tabs.List>
<Tabs.Tab />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Panel />
</Tabs.Root>API reference
Root
Groups the tabs and the corresponding panels.
Renders a <div> element.
defaultValueTabs.Tab.Value0
- Name
- Description
The default value. Use when the component is not controlled. When the value is
null, no Tab will be active.- Type
Tabs.Tab.Value- Default
0
valueTabs.Tab.Value—
- Name
- Description
The value of the currently active
Tab. Use when the component is controlled. When the value isnull, no Tab will be active.- Type
Tabs.Tab.Value
onValueChangefunction—
- Name
- Description
Callback invoked when new value is being set.
- Type
| (( value: Tabs.Tab.Value, eventDetails: Tabs.Root.ChangeEventDetails< 'none', { activationDirection: Tabs.Tab.ActivationDirection } >, ) => void) | undefined
orientationTabs.Root.Orientation'horizontal'
- Name
- Description
The component orientation (layout flow direction).
- Type
'horizontal' | 'vertical' | undefined- Default
'horizontal'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Root.State) => string | undefined)
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | ((state: Tabs.Root.State) => CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Root.State, ) => ReactElement)
data-orientation
data-activation-direction
List
Groups the individual tab buttons.
Renders a <div> element.
activateOnFocusbooleanfalse
- Name
- Description
Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using Enter or Space key press.
- Type
boolean | undefined- Default
false
loopFocusbooleantrue
- Name
- Description
Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
- Type
boolean | undefined- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.List.State) => string | undefined)
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | ((state: Tabs.List.State) => CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.List.State, ) => ReactElement)
data-orientation
data-activation-direction
Tab
An individual interactive tab button that toggles the corresponding panel.
Renders a <button> element.
value*Tabs.Tab.Value—
- Name
- Description
The value of the Tab.
- Type
Tabs.Tab.Value
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Tab.State) => string | undefined)
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | ((state: Tabs.Tab.State) => CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Tab.State, ) => ReactElement)
data-orientation
data-disabled
data-activation-direction
data-active
Indicator
A visual indicator that can be styled to match the position of the currently active tab.
Renders a <span> element.
renderBeforeHydrationbooleanfalse
- Description
Whether to render itself before React hydrates. This minimizes the time that the indicator isn’t visible after server-side rendering.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Indicator.State) => string | undefined)
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: Tabs.Indicator.State, ) => CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Indicator.State, ) => ReactElement)
data-orientation
data-activation-direction
--active-tab-bottom
--active-tab-height
--active-tab-left
--active-tab-right
--active-tab-top
--active-tab-width
Panel
A panel displayed when the corresponding tab is active.
Renders a <div> element.
value*Tabs.Tab.Value—
- Name
- Description
The value of the TabPanel. It will be shown when the Tab with the corresponding value is active.
- Type
Tabs.Tab.Value
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Panel.State) => string | undefined)
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | ((state: Tabs.Panel.State) => CSSProperties | undefined) | undefined
keepMountedbooleanfalse
- Name
- Description
Whether to keep the HTML element in the DOM while the panel is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Panel.State, ) => ReactElement)