ナビゲーション

v2.1.0
ナビゲーション

タブバー

小さな画面の下端に主要な移動先を並べるナビゲーションです。

このページの内容

タブバーは、小さな画面のアプリで主要な移動先を 3〜5 個、親指が届きやすい下端に並べます。各項目はアイコンと、その下の短いラベルで構成されます。現在の項目にはインク色を使い、アイコンの背後には淡いピル型の背景を敷きます。ほかの項目は無彩色です。バーはすりガラス調で、上端に細い罫線があり、ホームインジケーターと重ならないように余白を確保します。

タブバー

<div class="well h(320) max-w(380) mx-auto overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar" aria-label="Main">    <a class="tabbar-item" href="#" aria-current="page">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4 16.25L4 8.5672A1.25 1.25 0 0 1 4.4269 7.6265L9.1769 3.4702A1.25 1.25 0 0 1 10.8231 3.4702L15.5731 7.6265A1.25 1.25 0 0 1 16 8.5672L16 16.25A1.25 1.25 0 0 1 14.75 17.5L5.25 17.5A1.25 1.25 0 0 1 4 16.25Z" /><path d="M8 17.5L8 13.5A1 1 0 0 1 9 12.5L11 12.5A1 1 0 0 1 12 13.5L12 17.5" />      </svg><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" />      </svg><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.5 2.5L2.5 17.5" /><path d="M6.6667 5L6.6667 17.5" /><path d="M10.8333 4.1667L10.8333 17.5" /><path d="M14.1667 4.1667L18.3333 17.0833" />      </svg><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="10" cy="5.6" r="3" /><path d="M4 17.25V15.75C4 13.4 6.95 11.9 8.85 11.9H11.15C13.05 11.9 16 13.4 16 15.75V17.25" />      </svg><span class="tabbar-label">Profile</span>    </a>  </nav></div>
import HomeIcon from '@master/icons-react/native/20/soft/home'import SearchIcon from '@master/icons-react/native/20/soft/search'import LibraryIcon from '@master/icons-react/native/20/soft/library'import UserIcon from '@master/icons-react/native/20/soft/user'<div className="well h(320) max-w(380) mx-auto overflow-y-auto">  <div className="grid gap-sm p-md">    <div className="sheet p-lg text-sm">Today</div>    <div className="sheet p-lg text-sm">Continue reading</div>    <div className="sheet p-lg text-sm">New this week</div>    <div className="sheet p-lg text-sm">From your library</div>  </div>  <nav className="tabbar" aria-label="Main">    <a className="tabbar-item" href="#" aria-current="page">      <HomeIcon className="icon" /><span className="tabbar-label">Home</span>    </a>    <a className="tabbar-item" href="#">      <SearchIcon className="icon" /><span className="tabbar-label">Search</span>    </a>    <a className="tabbar-item" href="#">      <LibraryIcon className="icon" /><span className="tabbar-label">Library</span>    </a>    <a className="tabbar-item" href="#">      <UserIcon className="icon" /><span className="tabbar-label">Profile</span>    </a>  </nav></div>
<script>  import HomeIcon from '@master/icons-svelte/native/20/soft/home'  import SearchIcon from '@master/icons-svelte/native/20/soft/search'  import LibraryIcon from '@master/icons-svelte/native/20/soft/library'  import UserIcon from '@master/icons-svelte/native/20/soft/user'</script><div class="well h(320) max-w(380) mx-auto overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar" aria-label="Main">    <a class="tabbar-item" href="#" aria-current="page">      <HomeIcon class="icon" /><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#">      <SearchIcon class="icon" /><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <UserIcon class="icon" /><span class="tabbar-label">Profile</span>    </a>  </nav></div>
<script setup>import HomeIcon from '@master/icons-vue/native/20/soft/home'import SearchIcon from '@master/icons-vue/native/20/soft/search'import LibraryIcon from '@master/icons-vue/native/20/soft/library'import UserIcon from '@master/icons-vue/native/20/soft/user'</script><template>  <div class="well h(320) max-w(380) mx-auto overflow-y-auto">    <div class="grid gap-sm p-md">      <div class="sheet p-lg text-sm">Today</div>      <div class="sheet p-lg text-sm">Continue reading</div>      <div class="sheet p-lg text-sm">New this week</div>      <div class="sheet p-lg text-sm">From your library</div>    </div>    <nav class="tabbar" aria-label="Main">      <a class="tabbar-item" href="#" aria-current="page">        <HomeIcon class="icon" /><span class="tabbar-label">Home</span>      </a>      <a class="tabbar-item" href="#">        <SearchIcon class="icon" /><span class="tabbar-label">Search</span>      </a>      <a class="tabbar-item" href="#">        <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>      </a>      <a class="tabbar-item" href="#">        <UserIcon class="icon" /><span class="tabbar-label">Profile</span>      </a>    </nav>  </div></template>
プレビューをスクロールすると、コンテンツがバーの下を通ります。

バーはスクロールコンテナーの下端に position: sticky で配置します。シェル全体をスクロールしないアプリでは、スクロール領域の直後に配置しても同じ見た目になります。

タブバーコンポーネントが定義するのはバー自体です。ページ内のどこに置くかはレイアウトで決まります。ページ ではメイン領域の後ろに置き、固定シェル ではフッターに配置します。

#フローティング

tabbar-floating はバーを端から離して余白を設け、サーフェスと同じ角丸を使い、浮き上がって見えるように影を付けます。

フローティング

<div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar tabbar-floating" aria-label="Main">    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4 16.25L4 8.5672A1.25 1.25 0 0 1 4.4269 7.6265L9.1769 3.4702A1.25 1.25 0 0 1 10.8231 3.4702L15.5731 7.6265A1.25 1.25 0 0 1 16 8.5672L16 16.25A1.25 1.25 0 0 1 14.75 17.5L5.25 17.5A1.25 1.25 0 0 1 4 16.25Z" /><path d="M8 17.5L8 13.5A1 1 0 0 1 9 12.5L11 12.5A1 1 0 0 1 12 13.5L12 17.5" />      </svg><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#" aria-current="page">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" />      </svg><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.5 2.5L2.5 17.5" /><path d="M6.6667 5L6.6667 17.5" /><path d="M10.8333 4.1667L10.8333 17.5" /><path d="M14.1667 4.1667L18.3333 17.0833" />      </svg><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="10" cy="5.6" r="3" /><path d="M4 17.25V15.75C4 13.4 6.95 11.9 8.85 11.9H11.15C13.05 11.9 16 13.4 16 15.75V17.25" />      </svg><span class="tabbar-label">Profile</span>    </a>  </nav></div>
import HomeIcon from '@master/icons-react/native/20/soft/home'import SearchIcon from '@master/icons-react/native/20/soft/search'import LibraryIcon from '@master/icons-react/native/20/soft/library'import UserIcon from '@master/icons-react/native/20/soft/user'<div className="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div className="grid gap-sm p-md">    <div className="sheet p-lg text-sm">Today</div>    <div className="sheet p-lg text-sm">Continue reading</div>    <div className="sheet p-lg text-sm">New this week</div>    <div className="sheet p-lg text-sm">From your library</div>  </div>  <nav className="tabbar tabbar-floating" aria-label="Main">    <a className="tabbar-item" href="#">      <HomeIcon className="icon" /><span className="tabbar-label">Home</span>    </a>    <a className="tabbar-item" href="#" aria-current="page">      <SearchIcon className="icon" /><span className="tabbar-label">Search</span>    </a>    <a className="tabbar-item" href="#">      <LibraryIcon className="icon" /><span className="tabbar-label">Library</span>    </a>    <a className="tabbar-item" href="#">      <UserIcon className="icon" /><span className="tabbar-label">Profile</span>    </a>  </nav></div>
<script>  import HomeIcon from '@master/icons-svelte/native/20/soft/home'  import SearchIcon from '@master/icons-svelte/native/20/soft/search'  import LibraryIcon from '@master/icons-svelte/native/20/soft/library'  import UserIcon from '@master/icons-svelte/native/20/soft/user'</script><div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar tabbar-floating" aria-label="Main">    <a class="tabbar-item" href="#">      <HomeIcon class="icon" /><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#" aria-current="page">      <SearchIcon class="icon" /><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <UserIcon class="icon" /><span class="tabbar-label">Profile</span>    </a>  </nav></div>
<script setup>import HomeIcon from '@master/icons-vue/native/20/soft/home'import SearchIcon from '@master/icons-vue/native/20/soft/search'import LibraryIcon from '@master/icons-vue/native/20/soft/library'import UserIcon from '@master/icons-vue/native/20/soft/user'</script><template>  <div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">    <div class="grid gap-sm p-md">      <div class="sheet p-lg text-sm">Today</div>      <div class="sheet p-lg text-sm">Continue reading</div>      <div class="sheet p-lg text-sm">New this week</div>      <div class="sheet p-lg text-sm">From your library</div>    </div>    <nav class="tabbar tabbar-floating" aria-label="Main">      <a class="tabbar-item" href="#">        <HomeIcon class="icon" /><span class="tabbar-label">Home</span>      </a>      <a class="tabbar-item" href="#" aria-current="page">        <SearchIcon class="icon" /><span class="tabbar-label">Search</span>      </a>      <a class="tabbar-item" href="#">        <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>      </a>      <a class="tabbar-item" href="#">        <UserIcon class="icon" /><span class="tabbar-label">Profile</span>      </a>    </nav>  </div></template>

#使用場面

ユーザーが日常的に行き来する、重要度が同じ移動先にはタブバーを使います。同じページ内のビューを切り替えるには タブ を使います。画面が広い場合は、同じ移動先を ナビゲーションバー または ナビゲーション に配置します。ラベルは一語に収めます。収まりきらないラベルは、隣の項目を押しのけないよう、省略記号で切り詰められます。

#アクセシビリティ

  • バーにはラベル付きの <nav> を使い、各項目をリンクにします。現在のリンクには aria-current="page" を指定します。同じ画面内でパネルを切り替える場合は、role="tablist" に role="tab" と aria-selected を組み合わせます。現在の項目と選択中のタブは、同じ見た目になります。
  • すべての項目にラベルを表示します。アイコンだけでは意味を判断しにくいため、その下に移動先の名前を添えます。
  • 各項目の高さは 56px 以上で、バーの幅を均等に分け合います。高さはタッチ領域に必要な 44px を十分に上回ります。
  • バーは項目の下に env(safe-area-inset-bottom) を追加します。この余白を適用するには、ビューポートのメタタグに viewport-fit=cover を指定します。

#クラス

クラス説明
tabbarラベル付きの nav に適用すると、すりガラス状のバーが下端に貼り付きます。各項目はバーの幅を均等に分け合います。
tabbar-floating画面端から離して浮かせたバー。余白、サーフェスの角の形状、浮遊感を出す影付きtabbar と併用します
tabbar-item移動先を示すリンクまたはボタン。tabbar-labelの上にアイコンを配置
tabbar-labelアイコン下の1行ラベル。隣の項目を押し広げないよう、はみ出す部分は省略記号で切り詰める

#カスタムプロパティ

プロパティ既定値説明
--tabbar-height3.5rem項目の最小高さ
--tabbar-colorvar(--color-surface-base)パネルに色味を加える色

#ソース

@master/ui/components/tabbar.css
/* * Tab bar: the few main destinations of a small-screen app, along the bottom edge under the thumb. * Each item is an icon over a short label. The current one is in ink and its icon rests on a soft pill. * The bar is a pane of frosted glass with a hairline above it, and it keeps clear of the home indicator. */@layer components.ui {  .tabbar {    --tabbar-height: 3.5rem;    --tabbar-color: var(--color-surface-base);    position: sticky;    bottom: 0;    z-index: 20;    display: grid;    grid-auto-columns: minmax(0, 1fr);    grid-auto-flow: column;    min-width: 0;    margin: 0;    /* Clear of the home indicator below and, on a phone turned on its side, of the notch at either end. */    padding: 0 max(.25rem, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(.25rem, env(safe-area-inset-left, 0px));    background: color-mix(in oklab, var(--tabbar-color) 78%, transparent);    box-shadow: inset 0 .5px 0 var(--color-line-strong);    backdrop-filter: blur(16px) saturate(1.7);    list-style: none;    /* Floating: a bar lifted off the edge, with the corner of a surface. */    &.tabbar-floating {      --tabbar-color: var(--color-surface-floating);      bottom: max(.75rem, env(safe-area-inset-bottom, 0px));      /* Its sides keep clear of a phone's notch too, turned on its side, as the edge bar's padding does. */      margin: .75rem max(.75rem, env(safe-area-inset-right, 0px)) .75rem max(.75rem, env(safe-area-inset-left, 0px));      padding: 0 .25rem;      border-radius: calc(var(--radius-surface) * var(--corner-scale) + 4px);      corner-shape: var(--corner-shape);      box-shadow: var(--shadow-floating);    }    @media (prefers-reduced-transparency: reduce) {      background: var(--tabbar-color);      backdrop-filter: none;    }    /* An outline, not a border: the bar keeps its height and the floating bar its corner. */    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      background: Canvas;    }  }  .tabbar-item {    --icon-size: 1.25rem;    position: relative;    display: flex;    flex-direction: column;    align-items: center;    justify-content: center;    gap: .25rem;    min-width: 0;    min-height: var(--tabbar-height);    margin: 0;    padding: .375rem .25rem;    border: 0;    background: transparent;    color: var(--color-text-muted);    font: var(--font-weight-control) .6875rem/1 var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: .005em;    text-decoration: none;    cursor: pointer;    touch-action: manipulation;    isolation: isolate;    -webkit-tap-highlight-color: transparent;    transition: color var(--duration-quick) var(--easing-glide);    user-select: none;    -webkit-user-select: none;    /*     * The pill behind the icon: 56 by 28, centered on the icon's row, which stands half the gap and the 11px     * label above the item's middle. It grows in from a little smaller.     */    &::before {      content: '';      position: absolute;      top: calc(50% - (.25rem + .6875rem) / 2 - .875rem);      left: calc(50% - 1.75rem);      z-index: -1;      width: 3.5rem;      height: 1.75rem;      border-radius: 999px;      background: var(--color-surface-chip);      box-shadow: inset 0 0 0 .5px var(--color-line-hair);      opacity: 0;      scale: .8 .9;      transition-property: opacity, scale;      transition-duration: var(--duration-base);      transition-timing-function: var(--easing-glide);    }    @media (hover: hover) {      &:hover {        color: var(--color-text-strong);      }    }    &:is([aria-current="page"], [aria-selected="true"]) {      color: var(--color-text-strong);      &::before {        opacity: 1;        scale: 1;      }    }    &:active:not(:disabled, [aria-disabled="true"])::before {      opacity: 1;      scale: .94;      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;      outline-offset: -4px;      border-radius: calc(var(--radius-control) * var(--corner-scale));      corner-shape: var(--corner-shape);    }    /* The pill fades in without growing, and a press does not shrink it. */    @media (prefers-reduced-motion: reduce) {      &::before, &:active:not(:disabled, [aria-disabled="true"])::before {        scale: none;      }    }    @media (forced-colors: active) {      &:is([aria-current="page"], [aria-selected="true"]) {        color: Highlight;      }    }    &:is(:disabled, [aria-disabled="true"]) {      color: var(--color-text-disabled);      cursor: not-allowed;      @media (forced-colors: active) {        color: GrayText;      }    }  }  /* The word under the icon: one line, cut with an ellipsis before it pushes its neighbors. */  .tabbar-label {    overflow: hidden;    max-width: 100%;    /*     * A line as tall as the letters would clip the descenders of y, g and p at the ellipsis's edge. The line is a     * quarter taller and the margin takes that back, so the item and the pill above it keep their places.     */    margin-block: -.0859375rem;    line-height: 1.25;    text-overflow: ellipsis;    white-space: nowrap;  }}