Tabs
Segmented tabs built on the Bootstrap Tab plugin, with arrow-key navigation.
Installation
bash
npx bootcn add tabsbash
pnpm dlx bootcn add tabsbash
yarn dlx bootcn add tabsbash
bunx --bun bootcn add tabsThe CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.
Usage
html
<div class="bootcn-tabs">
<div class="nav bootcn-tabs__list" role="tablist" aria-label="Account settings">
<button
class="nav-link active"
id="tab-account"
type="button"
role="tab"
data-bs-toggle="tab"
data-bs-target="#panel-account"
aria-controls="panel-account"
aria-selected="true"
>
Account
</button>
<button
class="nav-link"
id="tab-password"
type="button"
role="tab"
data-bs-toggle="tab"
data-bs-target="#panel-password"
aria-controls="panel-password"
aria-selected="false"
tabindex="-1"
>
Password
</button>
</div>
<div class="tab-content">
<div
class="tab-pane fade show active bootcn-tabs__panel"
id="panel-account"
role="tabpanel"
aria-labelledby="tab-account"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade bootcn-tabs__panel"
id="panel-password"
role="tabpanel"
aria-labelledby="tab-password"
tabindex="0"
>
...
</div>
</div>
</div>Each tab needs a unique id, and its panel must reference it with aria-labelledby. When the list is wider than its container it scrolls horizontally.
Customizing
| Variable | Default |
|---|---|
--bootcn-tabs-list-bg | var(--bs-secondary-bg) |
--bootcn-tabs-list-padding | 0.25rem |
--bootcn-tabs-trigger-color | var(--bs-secondary-color) |
--bootcn-tabs-trigger-active-bg | var(--bs-body-bg) |
--bootcn-tabs-trigger-active-color | var(--bs-emphasis-color) |
Dependencies
- Bootstrap 5.3+ CSS and JavaScript bundle (Tab plugin).
themes/tokens/tokens.css.
Without Bootstrap's JavaScript only the first panel is visible.
Accessibility
role="tablist",role="tab"androle="tabpanel"witharia-controls/aria-labelledby, and anaria-labelon the list.- Only the active tab is in the tab order (
tabindex="-1"on the others); arrow keys move between tabs. - Panels have
tabindex="0"so keyboard users can reach content without focusable elements. - Bootstrap's fade is disabled under
prefers-reduced-motion.
Source
The exact files the CLI installs (tabs@1.1.0). View on GitHub · Report an issue
html
<div class="bootcn-tabs">
<div class="nav bootcn-tabs__list" role="tablist" aria-label="Account settings">
<button
class="nav-link active"
id="bootcn-tab-account"
type="button"
role="tab"
data-bs-toggle="tab"
data-bs-target="#bootcn-tabpanel-account"
aria-controls="bootcn-tabpanel-account"
aria-selected="true"
>
Account
</button>
<button
class="nav-link"
id="bootcn-tab-password"
type="button"
role="tab"
data-bs-toggle="tab"
data-bs-target="#bootcn-tabpanel-password"
aria-controls="bootcn-tabpanel-password"
aria-selected="false"
tabindex="-1"
>
Password
</button>
<button
class="nav-link"
id="bootcn-tab-team"
type="button"
role="tab"
data-bs-toggle="tab"
data-bs-target="#bootcn-tabpanel-team"
aria-controls="bootcn-tabpanel-team"
aria-selected="false"
tabindex="-1"
>
Team
</button>
</div>
<div class="tab-content">
<div
class="tab-pane fade show active bootcn-tabs__panel"
id="bootcn-tabpanel-account"
role="tabpanel"
aria-labelledby="bootcn-tab-account"
tabindex="0"
>
<p class="mb-0">Change your name, email and profile picture.</p>
</div>
<div
class="tab-pane fade bootcn-tabs__panel"
id="bootcn-tabpanel-password"
role="tabpanel"
aria-labelledby="bootcn-tab-password"
tabindex="0"
>
<p class="mb-0">Update your password and two-factor authentication.</p>
</div>
<div
class="tab-pane fade bootcn-tabs__panel"
id="bootcn-tabpanel-team"
role="tabpanel"
aria-labelledby="bootcn-tab-team"
tabindex="0"
>
<p class="mb-0">Invite people and manage their roles.</p>
</div>
</div>
</div>css
.bootcn-tabs {
--bootcn-tabs-list-bg: var(--bootcn-muted);
--bootcn-tabs-list-padding: 0.25rem;
--bootcn-tabs-trigger-color: var(--bs-secondary-color);
--bootcn-tabs-trigger-active-bg: var(--bs-body-bg);
--bootcn-tabs-trigger-active-color: var(--bs-emphasis-color);
min-width: 0;
}
.bootcn-tabs__list {
display: inline-flex;
flex-wrap: nowrap;
gap: 0.25rem;
max-width: 100%;
padding: var(--bootcn-tabs-list-padding);
overflow-x: auto;
border-radius: var(--bootcn-radius-lg);
background-color: var(--bootcn-tabs-list-bg);
}
.bootcn-tabs__list > .nav-link {
flex-shrink: 0;
padding: 0.25rem 0.75rem;
border: 0;
border-radius: var(--bootcn-radius);
font-size: 0.875rem;
line-height: 1.25rem;
background: transparent;
color: var(--bootcn-tabs-trigger-color);
font-weight: 500;
white-space: nowrap;
transition:
background-color var(--bootcn-transition),
color var(--bootcn-transition),
box-shadow var(--bootcn-transition);
}
.bootcn-tabs__list > .nav-link:hover {
color: var(--bootcn-tabs-trigger-active-color);
}
.bootcn-tabs__list > .nav-link.active {
background-color: var(--bootcn-tabs-trigger-active-bg);
color: var(--bootcn-tabs-trigger-active-color);
box-shadow: var(--bootcn-shadow-sm);
}
.bootcn-tabs__list > .nav-link:focus-visible {
outline: 0;
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-tabs__panel {
padding-top: 1rem;
}
.bootcn-tabs__panel:focus-visible {
outline: 0;
border-radius: var(--bootcn-radius-sm);
box-shadow: var(--bootcn-focus-ring);
}
