Skip to content

Tabs

Switch between related views without leaving the page. Same markup and props in every style: switch the style in the header to see it change.

Segmented

The default look. Arrow keys move between tabs. In HTML, add data-vin-tabs and include vinui.js once.

Change your name, email and profile picture.
tabs-segmented.html
<div class="vin-tabs" data-vin-tabs style="width: 100%; max-width: 380px">
  <div class="vin-tabs__list" role="tablist" aria-label="Account settings">
    <button type="button" class="vin-tabs__tab" role="tab" id="ta-account" aria-selected="true" aria-controls="ta-account-panel">Account</button>
    <button type="button" class="vin-tabs__tab" role="tab" id="ta-password" aria-selected="false" aria-controls="ta-password-panel" tabindex="-1">Password</button>
    <button type="button" class="vin-tabs__tab" role="tab" id="ta-team" aria-selected="false" aria-controls="ta-team-panel" tabindex="-1">Team</button>
  </div>
  <div class="vin-tabs__panel" role="tabpanel" id="ta-account-panel" aria-labelledby="ta-account" tabindex="0">Change your name, email and profile picture.</div>
  <div class="vin-tabs__panel" role="tabpanel" id="ta-password-panel" aria-labelledby="ta-password" tabindex="0" hidden>Update your password and turn on two-step sign-in.</div>
  <div class="vin-tabs__panel" role="tabpanel" id="ta-team-panel" aria-labelledby="ta-team" tabindex="0" hidden>Invite people and manage their roles.</div>
</div>

Line

Underlined tabs for page sections and settings screens.

12 open tasks, 3 due this week.
tabs-line.html
<div class="vin-tabs vin-tabs--line" data-vin-tabs style="width: 100%; max-width: 420px">
  <div class="vin-tabs__list" role="tablist" aria-label="Project">
    <button type="button" class="vin-tabs__tab" role="tab" id="tb-overview" aria-selected="true" aria-controls="tb-overview-panel">Overview</button>
    <button type="button" class="vin-tabs__tab" role="tab" id="tb-activity" aria-selected="false" aria-controls="tb-activity-panel" tabindex="-1">Activity</button>
    <button type="button" class="vin-tabs__tab" role="tab" id="tb-files" aria-selected="false" aria-controls="tb-files-panel" tabindex="-1">Files</button>
    <button type="button" class="vin-tabs__tab" role="tab" id="tb-archive" aria-selected="false" aria-controls="tb-archive-panel" tabindex="-1" disabled>Archive</button>
  </div>
  <div class="vin-tabs__panel" role="tabpanel" id="tb-overview-panel" aria-labelledby="tb-overview" tabindex="0">12 open tasks, 3 due this week.</div>
  <div class="vin-tabs__panel" role="tabpanel" id="tb-activity-panel" aria-labelledby="tb-activity" tabindex="0" hidden>Latest changes from your team.</div>
  <div class="vin-tabs__panel" role="tabpanel" id="tb-files-panel" aria-labelledby="tb-files" tabindex="0" hidden>Shared documents and images.</div>
  <div class="vin-tabs__panel" role="tabpanel" id="tb-archive-panel" aria-labelledby="tb-archive" tabindex="0" hidden>Archived items.</div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add tabs
React
import { Tabs, TabList, Tab, TabPanel } from "@/components/vin/tabs";
Vue
import Tabs, { TabList, Tab, TabPanel } from "@/components/vin/tabs.vue";
Svelte
import Tabs from "$lib/components/vin/tabs.svelte";
import TabList from "$lib/components/vin/tabs-list.svelte";
import TabPanel from "$lib/components/vin/tabs-panel.svelte";
import Tab from "$lib/components/vin/tabs-tab.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/tabs.json, which every framework version is tested against.

PropValuesDefaultIn HTML
variantsegmentedlinesegmentedvin-tabs--line
value / defaultValue
The open tab (controlled or not). Use onValueChange to hear about changes.
string—aria-selected="true" on the tab
TabList aria-label
Names the group of tabs for screen readers.
string—aria-label on [role=tablist]
Tab / TabPanel value
Links each tab to its panel.
string—aria-controls / aria-labelledby
disabled (Tab)booleanfalsedisabled attribute

Parts

React, Vue, SvelteHTML classes
<Tabs><TabList><Tab><TabPanel>.vin-tabs.vin-tabs--line.vin-tabs__list.vin-tabs__tab.vin-tabs__panel

Accessibility

  • Follows the WAI-ARIA tabs pattern: role="tablist", "tab" and "tabpanel", linked with aria-controls and aria-labelledby.
  • Only the open tab is in the Tab order; ← → move between tabs and Home/End jump to the first or last. Right-to-left layouts flip the arrows.
  • Panels can take focus, so keyboard users reach their content straight after the tabs.
  • The open tab is shown by more than colour: a raised surface or an underline.