Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Tabs

    Tabs for switching between content panels, with WAI-ARIA keyboard navigation.

    Change your account name and email.
    Change your account name and email.
    Change your account name and email.
    Change your account name and email.
    Change your account name and email.
    <x-markas.tabs :items="['account' => 'Account', 'password' => 'Password', 'notifications' => 'Notifications']" default-value="account">
        <x-slot:account>Change your account name and email.</x-slot:account>
        <x-slot:password>Change your password regularly.</x-slot:password>
        <x-slot:notifications>Choose which emails you want to receive.</x-slot:notifications>
    </x-markas.tabs>
    import { Tabs } from "@/components/markas/Tabs";
    
    const items = [
      {
        value: "account",
        label: "Account",
        content: "Change your account name and email.",
      },
      {
        value: "password",
        label: "Password",
        content: "Change your password regularly.",
      },
      {
        value: "notifications",
        label: "Notifications",
        content: "Choose which emails you want to receive.",
      },
    ];
    
    export default function TabsExample() {
      return <Tabs items={items} defaultValue="account" />;
    }
    <script setup lang="ts">
    import Tabs from "@/components/markas/Tabs.vue";
    
    const items = [
      { value: "account", label: "Account" },
      { value: "password", label: "Password" },
      { value: "notifications", label: "Notifications" },
    ];
    </script>
    
    <template>
      <Tabs :items="items" default-value="account">
        <template #account>Change your account name and email.</template>
        <template #password>Change your password regularly.</template>
        <template #notifications>Choose which emails you want to receive.</template>
      </Tabs>
    </template>
    <script lang="ts">
      import Tabs from "$lib/components/markas/Tabs.svelte";
    
      const items = [
        {
          value: "account",
          label: "Account",
          content: "Change your account name and email.",
        },
        {
          value: "password",
          label: "Password",
          content: "Change your password regularly.",
        },
        {
          value: "notifications",
          label: "Notifications",
          content: "Choose which emails you want to receive.",
        },
      ];
    </script>
    
    <Tabs {items} defaultValue="account" />
    ---
    import Tabs from "@/components/markas/Tabs.astro";
    
    const items = [
      { value: "account", label: "Account" },
      { value: "password", label: "Password" },
      { value: "notifications", label: "Notifications" },
    ];
    ---
    
    <Tabs items={items} defaultValue="account">
      <Fragment slot="account">Change your account name and email.</Fragment>
      <Fragment slot="password">Change your password regularly.</Fragment>
      <Fragment slot="notifications">Choose which emails you want to receive.</Fragment>
    </Tabs>
    import { Component } from "@angular/core";
    import { TabPanel, Tabs } from "./markas/tabs.component";
    
    @Component({
      selector: "markas-example",
      imports: [Tabs, TabPanel],
      template: `
        <markas-tabs [items]="items" defaultValue="account">
          <ng-template markasTabPanel="account"
            >Change your account name and email.</ng-template
          >
          <ng-template markasTabPanel="password"
            >Change your password regularly.</ng-template
          >
          <ng-template markasTabPanel="notifications"
            >Choose which emails you want to receive.</ng-template
          >
        </markas-tabs>
      `,
    })
    export default class TabsExample {
      protected readonly items = [
        { value: "account", label: "Account" },
        { value: "password", label: "Password" },
        { value: "notifications", label: "Notifications" },
      ];
    }

    Examples

    In a card

    Visitors 12,480
    Sign-ups 342
    Conversion 2.7%
    Visitors12,480
    Sign-ups342
    Conversion2.7%
    Visitors12,480
    Sign-ups342
    Conversion2.7%
    Visitors 12,480
    Sign-ups 342
    Conversion 2.7%
    Visitors12,480
    Sign-ups342
    Conversion2.7%

    With a form

    Full width

    $12 per month Billed monthly. Cancel anytime.
    $12 per monthBilled monthly. Cancel anytime.
    $12 per monthBilled monthly. Cancel anytime.
    $12 per month Billed monthly. Cancel anytime.
    $12 per monthBilled monthly. Cancel anytime.

    Empty state

    No open issues New issues from your team will show up here.
    No open issuesNew issues from your team will show up here.
    No open issuesNew issues from your team will show up here.
    No open issues New issues from your team will show up here.
    No open issuesNew issues from your team will show up here.

    Installation

    npx markasui@latest add tabs

    Usage

    <x-markas.tabs :items="['account' => 'Account', 'password' => 'Password']" default-value="account">
        <x-slot:account>Change your account name and email.</x-slot:account>
        <x-slot:password>Change your password regularly.</x-slot:password>
    </x-markas.tabs>

    Needs Alpine.js.

    import { Tabs } from "@/components/markas/Tabs";
    
    <Tabs
      defaultValue="account"
      items={[
        {
          value: "account",
          label: "Account",
          content: "Change your account name and email.",
        },
        {
          value: "password",
          label: "Password",
          content: "Change your password regularly.",
        },
      ]}
    />;
    <template>
      <Tabs
        default-value="account"
        :items="[
          { value: 'account', label: 'Account' },
          { value: 'password', label: 'Password' },
        ]"
      >
        <template #account>Change your account name and email.</template>
        <template #password>Change your password regularly.</template>
      </Tabs>
    </template>
    <script lang="ts">
      import Tabs from "$lib/components/markas/Tabs.svelte";
    
      let active = $state("account");
      const items = [
        { value: "account", label: "Account", content: account },
        {
          value: "password",
          label: "Password",
          content: "Change your password regularly.",
        },
      ];
    </script>
    
    {#snippet account()}
      <p>Change your account name and <strong>email</strong>.</p>
    {/snippet}
    
    <Tabs {items} bind:value={active} />

    content is plain text or a snippet declared at the top level of the template.

    ---
    import Tabs from "@/components/markas/Tabs.astro";
    
    const items = [
      { value: "account", label: "Account" },
      { value: "password", label: "Password" },
    ];
    ---
    
    <Tabs items={items} defaultValue="account">
      <Fragment slot="account">Change your account name and email.</Fragment>
      <Fragment slot="password">Change your password regularly.</Fragment>
    </Tabs>

    A small client script handles clicks and the arrow keys. The selected tab dispatches a bubbling markas-change event with its value as detail.

    import { Component, signal } from "@angular/core";
    import { TabPanel, Tabs } from "./markas/tabs.component";
    
    @Component({
      selector: "app-settings",
      imports: [Tabs, TabPanel],
      template: `
        <markas-tabs [items]="items" [(value)]="active">
          <ng-template markasTabPanel="account">
            Change your account name and email.
          </ng-template>
          <ng-template markasTabPanel="password">
            Change your password regularly.
          </ng-template>
        </markas-tabs>
      `,
    })
    export class Settings {
      readonly active = signal("account");
      readonly items = [
        { value: "account", label: "Account" },
        { value: "password", label: "Password" },
      ];
    }

    Each panel is an <ng-template markasTabPanel="value">, so its content is only created when Angular renders that panel.

    • Tab keys become ids and slot names, so use only lowercase letters, digits, or underscores.
    • Tabs has no built-in text. Tab labels come from items, so pass them in your site’s language.

    Props

    NameTypeDefaultDescription
    itemsBlade: array<key, label> · React and Svelte: { value, label, content }[] · Vue, Astro, Angular: { value, label }[][]List of tabs. In Blade, Vue, and Astro, fill each panel through a slot named after its key or value. In Angular, use <ng-template markasTabPanel="value">. In Svelte, content is text or a snippet.
    defaultValuestringfirst tabTab that is active on first render.
    v-model / onValueChangestring-Vue uses v-model, React uses the onValueChange callback.
    bind:valuestring-Svelte only. Two-way binding of the active tab. Svelte also accepts onValueChange.
    [(value)] / valueChangemodel<string>-Angular only. Active tab with two-way binding; valueChange emits on every change.
    markas-changeCustomEvent<string>-Astro only. Bubbling event dispatched from the selected tab with its value as detail.

    Accessibility

    • Uses the tablist, tab, and tabpanel roles with aria-selected, aria-controls, and aria-labelledby.
    • Left and right arrows move between tabs (wrapping at the ends), Home and End jump to the first and last tab.
    • Only the active tab is in the Tab order (roving tabindex), so the next Tab moves into the panel.

    Related components

    More navigation components with the same classes in every framework.