Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-tabset shows a tabbed container with multiple content areas,
only one of which is visible at a time. Tabs are shown horizontally inline
with content shown below it, by default. Use tabs to separate information into logical sections based on functionality or use case.
A tabset can hold multiple lightning-tab components as part of its body. The first tab is activated by default.
Design
lightning-tabset implements the tabs blueprint in the Salesforce Lightning Design System (SLDS). The tabs adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
Use lightning-tabset to enable users to switch easily between tabs to perform tasks without leaving the page. Assign a default tab based on the most important use case for the page.
Here’s an example of a standard horizontal tabset.
1<template>2 <lightning-tabset>3 <lightning-tab label="Tab One"> Content of Tab One </lightning-tab>4 <lightning-tab label="Tab Two"> Content of Tab Two </lightning-tab>5 </lightning-tabset>6</template>
We don’t recommend by using tabs to define a linear, ordered process since each tab functions independently of the others.
Tab labels must be consistent. For example, use a verb to let users identify a tab’s purpose quickly.
lightning-tabset doesn’t currently support mobile-oriented tabs. This component doesn’t adjust the tab styling when there are two or more immediately adjacent tab sets on mobile.
Add Content To Tab Programmatically
To add content programmatically to the tab body, use the onactive event handler on lightning-tab.
Here’s an example with two tabs, which loads content when the tabs are selected.
1<template>2 <lightning-tabset>3 <lightning-tab label="Item One" value="1" onactive={handleActive}>4 Here's the content for Item One: {tabContent}5 </lightning-tab>6 <lightning-tab label="Item Two" value="2" onactive={handleActive}>7 Here's the content for Item Two: {tabContent}8 </lightning-tab>9 </lightning-tabset>10</template>
Identify the active tab by using event.target.value.
1import{LightningElement}from "lwc";23export default class ActiveTabExample extends LightningElement{4 tabContent = "";56 handleActive(event){7 const tab = event.target;8 this.tabContent = `Tab ${event.target.value} is now active`;9}10}
Component Styling
Set the variant attribute to change the look of the tabset. The variant attribute can be set to default, scoped, or vertical.
Use a combination of the variant and class attributes to customize the tab content styles.
Variants
Specify the variant attribute with one of these values.
default creates global tabs. When you select a tab, its content replaces the content of the previously selected tab. The default variant tab encapsulates the content underneath it without enclosing it visually.
scoped creates a tab set that has a closed container with a defined border. Scoped tabs are useful for stacking several tabbed sections, where you want to change only a portion of the content to show. When you click those tabs, the content at the bottom remains the same while the content at the top changes for the activity.
vertical resembles the scoped variant in appearance, but the tabs appear vertically to the side instead of on the top.
You can nest scoped tabs within a global tab set, but don’t nest global tabs. If additional hierarchy is necessary, consider using a lightning-tree component.
Utility Classes
To apply additional styling, use the SLDS utility classes with the class attribute.
This example adds a gray background and padding to the content area on the first tab by using SLDS classes.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
When a tabset contains more tabs than can fit in the viewport, the extra tabs are moved into an overflow dropdown menu next to the last visible tab. The active tab always shows and is never moved into the overflow.
Truncating the tab label isn’t supported. When the tab label has more characters than can fit the viewport, the extra characters are not truncated but are hidden from view.
You can nest lightning-tab within other elements such as <div> or <template>, for example to render tabs conditionally by using if:true and if:false. Otherwise, you must nest
lightning-tab directly within lightning-tabset tags.
Tab content is lazy loaded; only the active and previously
active tabs content is queryable. In the example, the text Content of Tab Two is inserted in the DOM of the page only when the second tab is selected.
Use the Tab or arrow keys to navigate to the More menu that’s created when the viewport is too narrow to show all the tabs.
Several attributes enable accessibility features for a tabset heading.
Use heading-label to specify custom assistive text for a tabset heading. The value of heading-label is rendered as the text content of a div element with role="heading" and aria-level="2". If you don’t specify heading-label the default assistive text is “Tabs” in a div element with aria-level="2".
Use heading-level to pass a value between 1 and 6 to the rendered aria-level attribute. The default value is 2. This attribute requires you to also specify heading-label.
Specify heading-visible to display the assistive text above the tabset when you specify heading-label. By default, this attribute is not present so the assistive text is read by screen readers but isn’t displayed. When heading-visible is present, the assistive text is read by screen readers and displayed.
This example sets custom assistive text for a heading, specifies heading-level to change the rendered aria-level, and makes the heading visible.
1<template>2 <lightning-tabset heading-label="Example tabset" heading-level="3" heading-visible>3 <lightning-tab label="Item One"> One Content! </lightning-tab>4 <lightning-tab label="Item Two"> Two Content! </lightning-tab>5 </lightning-tabset>6</template>
Attributes
Name
Description
Type
Default
Required
active-tab-value
Sets a specific tab to open by default using a string that matches a tab's value string. If not used, the first tab opens by default.
string
heading-label
Specifies text to use as custom assistive text for the tabset heading. The text is placed in a div element with role="heading" and aria-level="2". When heading-label isn't specified, the default assistive text is "Tabs" in a div element with aria-level="2".
string|null
heading-level
Specifies the value to pass through to aria-level when you specify heading-label. Accepts values from 1 to 6. The default value is 2.
number
heading-visible
Determines whether the text that's passed with the heading-label attribute is visible above the tabset. This attribute isn't present by default so the assistive text is only read by screen readers.
boolean
title
Displays tooltip text when the mouse moves over the tabset.
string
variant
The variant changes the appearance of the tabset. Accepted variants are standard, scoped, and vertical.