Tabs are a set of layered sections of content that are displayed individually and toggled through.
Consequat sint dolor incididunt
Ex do nulla elit amet et laboris tempor qui nulla. Sunt amet voluptate enim dolore sit cupidatat. Incididunt ex non minim aliquip sunt eu. Est elit et eu enim sunt enim qui do adipisicing. Culpa veniam laboris nostrud tempor est minim irure fugiat sit aute laborum.
Veniam eu occaecat cillum ut anim esse minim anim veniam amet quis culpa excepteur aute. Nulla duis nostrud laborum Lorem esse ea consectetur sunt. Ut dolor eu sit ipsum Lorem enim non nisi incididunt in proident aliqua. Sunt cupidatat officia amet quis irure qui tempor ipsum labore deserunt occaecat enim labore id.
Aliqua occaecat voluptate laborum amet fugiat. Duis dolore exercitation id anim sit ut ipsum occaecat consectetur ullamco dolor consequat occaecat. Aute irure nisi sint minim id ad laboris et sunt do ad pariatur consectetur.
This component is comprised of several elements that work together to create a tablist. The following are the elements that make up the Tabs component.
API Reference
Root
The root element of the Tabs component. This element wraps the tablist and content elements and provides the scripting logic to toggle between tabs.
Prop
Type
Default
defaultValue
The default tab value to be selected on page load.
string
—
List
The list element of the Tabs component. This element wraps the tab trigger elements and is based on the <ul> element and can take in any generic HTML attributes.
Trigger
The trigger element of the Tabs component. This component is based on the <button> element and can take in any additional HTML attributes. The following are the custom props that can be passed to the component.
Prop
Type
Default
value *
The controlled value of the tab to bind to the correct content panel.
This value should pair with a tab content value, be unique within the set of tabs, and be in kebab-case.
string
—
Content
The content element of the Tabs component. This component is based on the <div> element and can take in any additional HTML attributes. The following are the custom props that can be passed to the component.
Prop
Type
Default
value *
The controlled value of the content to bind to the correct tab.
This value should pair with a tablist value, be unique within the set of tabs, and be in kebab-case.
string
—
Accessibility
The <Tabs> component has some predefined accessibility features that are important to consider when implementing it in your project. The following are some of the key accessibility features that are included in the component:
The component uses aria attributes to establish a clear association between the content and the tabs.
When a tab is activated, the corresponding content is brought into focus, enhancing the experience for users relying on keyboard navigation.
The component includes a hidden jump link within the content field that points back to the tab trigger.
Examples
Change the Default Tab
You can change the default tab that is opened when the component is first rendered by using the defaultValue prop on the <Tabs.Root> component.
Consequat sint dolor incididunt
Ex do nulla elit amet et laboris tempor qui nulla. Sunt amet voluptate enim dolore sit cupidatat. Incididunt ex non minim aliquip sunt eu. Est elit et eu enim sunt enim qui do adipisicing. Culpa veniam laboris nostrud tempor est minim irure fugiat sit aute laborum.
Veniam eu occaecat cillum ut anim esse minim anim veniam amet quis culpa excepteur aute. Nulla duis nostrud laborum Lorem esse ea consectetur sunt. Ut dolor eu sit ipsum Lorem enim non nisi incididunt in proident aliqua. Sunt cupidatat officia amet quis irure qui tempor ipsum labore deserunt occaecat enim labore id.
Aliqua occaecat voluptate laborum amet fugiat. Duis dolore exercitation id anim sit ut ipsum occaecat consectetur ullamco dolor consequat occaecat. Aute irure nisi sint minim id ad laboris et sunt do ad pariatur consectetur.
It’s recommended that an element like this is made as a reusable component. In this case, we have put together the following Astro compound component to serve as a blueprint for how you could possibly set up a Tabs component, and what properties and accessibility to consider.