Skip to content

Tabs

A component for toggling between related panels on the same page.

Workspace stats and activity.

Anatomy

Import the component and assemble its parts:

vue
<script setup lang="ts">
import {
  TabsIndicator,
  TabsList,
  TabsPanel,
  TabsRoot,
  TabsTab,
} from 'base-ui-vue'
</script>

<template>
  <TabsRoot>
    <TabsList>
      <TabsTab />
      <TabsIndicator />
    </TabsList>
    <TabsPanel />
  </TabsRoot>
</template>

Examples

Set as="a" and :native-button="false" on <TabsTab> to render tabs as links.

vue
<script setup lang="ts">
import { TabsList, TabsRoot, TabsTab } from 'base-ui-vue'
</script>

<template>
  <TabsRoot default-value="overview">
    <TabsList>
      <TabsTab as="a" href="/overview" :native-button="false" value="overview">
        Overview
      </TabsTab>
    </TabsList>
  </TabsRoot>
</template>

Controlled state

Use the value prop and value-change event for controlled behavior.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { TabsList, TabsPanel, TabsRoot, TabsTab } from 'base-ui-vue'

const value = ref('overview')
</script>

<template>
  <TabsRoot :value="value" @value-change="(nextValue) => value = nextValue">
    <TabsList>
      <TabsTab value="overview">Overview</TabsTab>
      <TabsTab value="projects">Projects</TabsTab>
    </TabsList>
    <TabsPanel value="overview">Overview panel</TabsPanel>
    <TabsPanel value="projects">Projects panel</TabsPanel>
  </TabsRoot>
</template>

API reference

Root

Groups the tabs and the corresponding panels. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node. Pass Slot for renderless mode.
default-valueTabsTabValue0The value of the Tab that should be active initially. Use when the component is uncontrolled. When the value is null, no Tab will be active.
valueTabsTabValueundefinedThe value of the currently active Tab. Use when the component is controlled. When the value is null, no Tab will be active.
orientation'horizontal' | 'vertical''horizontal'The component orientation.
classany | ((state: State) => any)undefinedCSS class applied to the element, or a function that returns a class based on the component state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component state.
EmitsTypeDescription
value-change(value, details) => voidEmitted when a new tab value is being set. details.reason is 'none' for user changes, 'initial' for the first automatic selection, 'disabled' when an uncontrolled selected tab becomes disabled, or 'missing' when an uncontrolled selected tab is removed or never mounts. User changes can be canceled with details.cancel().
AttributeTypeDescription
data-orientation'horizontal' | 'vertical'Indicates the orientation of the tabs.
data-activation-direction'left' | 'right' | 'up' | 'down' | 'none'Indicates the direction of the activation based on the previous active tab.

List

Groups the individual tab buttons. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node. Pass Slot for renderless mode.
activate-on-focusbooleanfalseWhether to automatically change the active tab on arrow key focus. Otherwise, tabs are activated with Enter, Space, or pointer press.
loop-focusbooleantrueWhether keyboard focus loops back to the first tab when the end of the list is reached.
classany | ((state: State) => any)undefinedCSS class applied to the element, or a function that returns a class based on the component state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component state.
AttributeTypeDescription
data-orientation'horizontal' | 'vertical'Indicates the orientation of the tabs.
data-activation-direction'left' | 'right' | 'up' | 'down' | 'none'Indicates the direction of the activation based on the previous active tab.

Tab

An individual interactive tab button that toggles the corresponding panel. Renders a <button> element.

PropTypeDefaultDescription
asstring | Component'button'The element or component to use for the root node. Pass Slot for renderless mode.
valueTabsTabValueundefinedThe value of the tab. When omitted, the tab's zero-based index is used.
disabledbooleanfalseWhether the tab should ignore user interaction. Disabled tabs remain focusable for composite keyboard navigation.
idstringundefinedThe id of the tab element.
native-buttonbooleantrueWhether the component renders a native <button> element. Set to false when using as with a non-button element.
classany | ((state: State) => any)undefinedCSS class applied to the element, or a function that returns a class based on the component state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component state.
AttributeTypeDescription
data-orientation'horizontal' | 'vertical'Indicates the orientation of the tabs.
data-disabled-Present when the tab is disabled.
data-active-Present when the tab is active.
data-activation-direction'left' | 'right' | 'up' | 'down' | 'none'Indicates the direction of the activation based on the previous active tab.

Indicator

A visual indicator that can be styled to match the position of the active tab. Renders a <span> element.

PropTypeDefaultDescription
asstring | Component'span'The element or component to use for the root node. Pass Slot for renderless mode.
classany | ((state: State) => any)undefinedCSS class applied to the element, or a function that returns a class based on the component state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component state.
AttributeTypeDescription
data-orientation'horizontal' | 'vertical'Indicates the orientation of the tabs.
data-activation-direction'left' | 'right' | 'up' | 'down' | 'none'Indicates the direction of the activation based on the previous active tab.
CSS VariableDescription
--active-tab-leftThe distance from the left side of the tab list to the active tab.
--active-tab-rightThe distance from the right side of the tab list to the active tab.
--active-tab-topThe distance from the top side of the tab list to the active tab.
--active-tab-bottomThe distance from the bottom side of the tab list to the active tab.
--active-tab-widthThe active tab width.
--active-tab-heightThe active tab height.

Panel

A panel displayed when the corresponding tab is active. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node. Pass Slot for renderless mode.
valueTabsTabValueRequiredThe value of the corresponding tab.
keep-mountedbooleanfalseWhether to keep the HTML element in the DOM while the panel is hidden.
idstringundefinedThe id of the tab panel element.
classany | ((state: State) => any)undefinedCSS class applied to the element, or a function that returns a class based on the component state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component state.
AttributeTypeDescription
data-orientation'horizontal' | 'vertical'Indicates the orientation of the tabs.
data-activation-direction'left' | 'right' | 'up' | 'down' | 'none'Indicates the direction of the activation based on the previous active tab.
data-hidden-Present when the panel is hidden.
data-index-Indicates the index of the tab panel.
data-starting-style-Present when the panel is animating in.
data-ending-style-Present when the panel is animating out.