ナビゲーション

v2.1.0
ナビゲーション

ステップ

購入手続きや初期設定のような短い手順の中での現在位置を、番号付きリストで示します。

このページの内容

ステップは、購入手続きや初期設定など、短い手順の中での現在位置を示します。順序付きリストを使い、CSS カウンターで各マーカーに番号を振ります。現在のステップにだけ aria-current="step" を付けると、スタイルシートがほかのステップの状態を判定します。

ステップ

<ol class="steps">  <li class="steps-item"><span class="steps-title">Account</span></li>  <li class="steps-item" aria-current="step"><span class="steps-title">Billing</span></li>  <li class="steps-item"><span class="steps-title">Confirm</span></li></ol>
<ol className="steps">  <li className="steps-item"><span className="steps-title">Account</span></li>  <li className="steps-item" aria-current="step"><span className="steps-title">Billing</span></li>  <li className="steps-item"><span className="steps-title">Confirm</span></li></ol>
<ol class="steps">  <li class="steps-item"><span class="steps-title">Account</span></li>  <li class="steps-item" aria-current="step"><span class="steps-title">Billing</span></li>  <li class="steps-item"><span class="steps-title">Confirm</span></li></ol>
<template>  <ol class="steps">    <li class="steps-item"><span class="steps-title">Account</span></li>    <li class="steps-item" aria-current="step"><span class="steps-title">Billing</span></li>    <li class="steps-item"><span class="steps-title">Confirm</span></li>  </ol></template>

#1 つの属性

1 つの属性で 3 つの状態が決まります。

  • 現在のステップには aria-current="step" を付けます。マーカーは小さなシートのように浮き上がり、インク色の輪郭が付きます。
  • 現在のステップより前のステップは完了です。判定には .steps-item:has(~ .steps-item[aria-current="step"]) を使います。マーカーはインク色の円からチェックマークを抜いた形です。チェック部分には下のサーフェスが透けるため、どちらのテーマでも見分けられます。次のステップへ伸びる線もインク色になります。
  • 残りのステップは未着手で、ウェルの中に番号を表示します。

属性を次の項目に移すと、3 つの状態がすべて更新されます。手順全体が終わると現在のステップはなくなります。リストに steps-complete を追加すると、すべてのステップが完了になります。

完了

<ol class="steps steps-complete">  <li class="steps-item"><span class="steps-title">Account</span></li>  <li class="steps-item"><span class="steps-title">Billing</span></li>  <li class="steps-item"><span class="steps-title">Confirm</span></li></ol>
<ol className="steps steps-complete">  <li className="steps-item"><span className="steps-title">Account</span></li>  <li className="steps-item"><span className="steps-title">Billing</span></li>  <li className="steps-item"><span className="steps-title">Confirm</span></li></ol>
<ol class="steps steps-complete">  <li class="steps-item"><span class="steps-title">Account</span></li>  <li class="steps-item"><span class="steps-title">Billing</span></li>  <li class="steps-item"><span class="steps-title">Confirm</span></li></ol>
<template>  <ol class="steps steps-complete">    <li class="steps-item"><span class="steps-title">Account</span></li>    <li class="steps-item"><span class="steps-title">Billing</span></li>    <li class="steps-item"><span class="steps-title">Confirm</span></li>  </ol></template>

#縦並び

steps-vertical を指定すると、ステップが縦に並びます。幅の狭い列や、各ステップに一文ずつ説明が付く場合に使います。テキストを steps-body で囲み、steps-description を追加します。

縦並び

<ol class="steps steps-vertical max-w(320) mx-auto">  <li class="steps-item">    <span class="steps-body">      <span class="steps-title">Create the project</span>      <span class="steps-description">Named atlas, in the Master workspace.</span>    </span>  </li>  <li class="steps-item" aria-current="step">    <span class="steps-body">      <span class="steps-title">Connect a repository</span>      <span class="steps-description">Choose where the code lives.</span>    </span>  </li>  <li class="steps-item">    <span class="steps-body">      <span class="steps-title">Deploy</span>      <span class="steps-description">The first build takes about a minute.</span>    </span>  </li></ol>
<ol className="steps steps-vertical max-w(320) mx-auto">  <li className="steps-item">    <span className="steps-body">      <span className="steps-title">Create the project</span>      <span className="steps-description">Named atlas, in the Master workspace.</span>    </span>  </li>  <li className="steps-item" aria-current="step">    <span className="steps-body">      <span className="steps-title">Connect a repository</span>      <span className="steps-description">Choose where the code lives.</span>    </span>  </li>  <li className="steps-item">    <span className="steps-body">      <span className="steps-title">Deploy</span>      <span className="steps-description">The first build takes about a minute.</span>    </span>  </li></ol>
<ol class="steps steps-vertical max-w(320) mx-auto">  <li class="steps-item">    <span class="steps-body">      <span class="steps-title">Create the project</span>      <span class="steps-description">Named atlas, in the Master workspace.</span>    </span>  </li>  <li class="steps-item" aria-current="step">    <span class="steps-body">      <span class="steps-title">Connect a repository</span>      <span class="steps-description">Choose where the code lives.</span>    </span>  </li>  <li class="steps-item">    <span class="steps-body">      <span class="steps-title">Deploy</span>      <span class="steps-description">The first build takes about a minute.</span>    </span>  </li></ol>
<template>  <ol class="steps steps-vertical max-w(320) mx-auto">    <li class="steps-item">      <span class="steps-body">        <span class="steps-title">Create the project</span>        <span class="steps-description">Named atlas, in the Master workspace.</span>      </span>    </li>    <li class="steps-item" aria-current="step">      <span class="steps-body">        <span class="steps-title">Connect a repository</span>        <span class="steps-description">Choose where the code lives.</span>      </span>    </li>    <li class="steps-item">      <span class="steps-body">        <span class="steps-title">Deploy</span>        <span class="steps-description">The first build takes about a minute.</span>      </span>    </li>  </ol></template>

前のステップに戻れる場合は、完了したステップのタイトルをリンクにします。未着手のステップは通常のテキストのままにします。

リンク付き

<nav aria-label="Checkout">  <ol class="steps">    <li class="steps-item"><a class="steps-title link link-quiet" href="#cart">Cart</a></li>    <li class="steps-item"><a class="steps-title link link-quiet" href="#shipping">Shipping</a></li>    <li class="steps-item" aria-current="step"><span class="steps-title">Payment</span></li>    <li class="steps-item"><span class="steps-title">Review</span></li>  </ol></nav>
<nav aria-label="Checkout">  <ol className="steps">    <li className="steps-item"><a className="steps-title link link-quiet" href="#cart">Cart</a></li>    <li className="steps-item">      <a className="steps-title link link-quiet" href="#shipping">Shipping</a>    </li>    <li className="steps-item" aria-current="step"><span className="steps-title">Payment</span></li>    <li className="steps-item"><span className="steps-title">Review</span></li>  </ol></nav>
<nav aria-label="Checkout">  <ol class="steps">    <li class="steps-item"><a class="steps-title link link-quiet" href="#cart">Cart</a></li>    <li class="steps-item"><a class="steps-title link link-quiet" href="#shipping">Shipping</a></li>    <li class="steps-item" aria-current="step"><span class="steps-title">Payment</span></li>    <li class="steps-item"><span class="steps-title">Review</span></li>  </ol></nav>
<template>  <nav aria-label="Checkout">    <ol class="steps">      <li class="steps-item"><a class="steps-title link link-quiet" href="#cart">Cart</a></li>      <li class="steps-item">        <a class="steps-title link link-quiet" href="#shipping">Shipping</a>      </li>      <li class="steps-item" aria-current="step"><span class="steps-title">Payment</span></li>      <li class="steps-item"><span class="steps-title">Review</span></li>    </ol>  </nav></template>

#アクセシビリティ

  • 手順の順序を伝えるために <ol> を使います。リストとしてマークアップすると、ステップの総数も読み上げられます。
  • aria-current="step" は、どのステップが現在のステップかを支援技術に伝えます。チェックマークとインク色は視覚的な手がかりなので、スクリーンリーダーではリスト内の順序が、どこまで完了したかを判断する手がかりになります。
  • 横並びにする場合は、短いタイトルのステップを 4〜5 個までに収めます。それを超える場合は steps-vertical を使います。

#クラス

クラス説明
stepsol に適用するステップのリスト。CSS カウンターでマーカーに番号を付け、隣り合うマーカーを線で結びます。
steps-verticalステップを縦に並べる配置。狭い列や、各ステップに1文ずつ添える場合に使用steps と併用します
steps-complete全ステップが完了し、進行中のステップがない状態steps と併用します
steps-itemli に適用するステップです。待機中はくぼみの中に番号を表示します。現在のステップより前にある場合は、前景色の円にチェックマークを表示します。
steps-bodyタイトルと説明の両方があるステップで、それらをまとめて囲みます。
steps-titleステップ名は 1 行で表示し、縦並びのリストでは折り返します。
steps-descriptionタイトルの下に置く控えめな 1 行

#カスタムプロパティ

プロパティ既定値説明
--steps-marker1.5remマーカーの直径

#ソース

@master/ui/components/steps.css
/* * Steps: where a reader is in a short sequence. An ordered list whose markers are numbered by a CSS counter. * Only the current step is marked, with aria-current="step": the steps before it are complete and take ink * and a check, and the steps after it wait in a well. A line joins each marker to the next. When the whole * sequence is done, steps-complete on the list completes every step. */@layer components.ui {  .steps {    --steps-marker: 1.5rem;    --steps-gap: .75rem;    display: flex;    gap: var(--steps-gap);    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-muted);    font-size: .8125rem;    line-height: 1.4;    list-style: none;    counter-reset: steps;    /* Every step is done: none is current, and the list rests in body ink. */    &.steps-complete {      color: var(--color-text-body);    }    /* One step under another, for a narrow column or steps that carry a sentence each. */    &.steps-vertical {      flex-direction: column;      gap: 0;    }  }  .steps-item {    position: relative;    display: flex;    flex: 1 1 0;    align-items: center;    gap: .5rem;    min-width: 0;    counter-increment: steps;    /*     * The last step has nothing to lead to, so it takes only the room it needs; where there is less, it still     * shrinks, so its title is cut like the others' instead of running out of the list.     */    &:last-child {      flex: 0 1 auto;    }    /* The marker: a number in a well while the step waits. */    &::before {      content: counter(steps);      display: grid;      flex: none;      place-items: center;      width: var(--steps-marker);      height: var(--steps-marker);      border-radius: 999px;      background: var(--color-surface-inset);      color: var(--color-text-muted);      box-shadow: var(--shadow-pressed);      font: var(--font-weight-control) .71875rem/1 var(--font-family-sans);      font-variant-numeric: tabular-nums;    }    /* The line to the next step. */    &:not(:last-child)::after {      content: '';      flex: 1 1 1rem;      min-width: 1rem;      height: 1px;      background: var(--color-line-divider);    }    /* Current: the marker rises as a small sheet with an ink contour, and the words take strong ink. */    &[aria-current="step"] {      color: var(--color-text-strong);      &::before {        @apply --surface-sheet;        color: var(--color-text-strong);        box-shadow: 0 0 0 .5px var(--color-text-strong), 0 0 0 1px color-mix(in oklab, var(--color-text-strong) 22%, transparent), 0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2);      }    }    /*     * Complete: every step that has the current one after it, or every step once the list is marked     * steps-complete. An ink disc with the check cut out of it, so the mark is the surface showing through     * and reads on moonstone and obsidian alike.     */    &:is(:has(~ .steps-item[aria-current="step"]), .steps-complete .steps-item) {      color: var(--color-text-body);      &::before {        content: '';        background: var(--color-surface-inverse);        box-shadow: none;        mask:          url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 8.4 2.6 2.6 5.4-6'/%3E%3C/svg%3E") center / .875rem no-repeat,          linear-gradient(black, black);        mask-composite: exclude;      }      &::after {        background: var(--color-text-strong);      }    }    @media (forced-colors: active) {      &::before {        outline: 1px solid CanvasText;        outline-offset: -1px;      }      &[aria-current="step"]::before {        outline: 2px solid Highlight;      }      /* The ink disc would be forced to the canvas, and its check with it: it keeps the text color instead. */      &:is(:has(~ .steps-item[aria-current="step"]), .steps-complete .steps-item)::before {        forced-color-adjust: none;        background: CanvasText;      }      /* As heavy as the line's own rules, the waiting one and the completed one, so neither keeps a theme color. */      &:not(:last-child)::after, &:is(:has(~ .steps-item[aria-current="step"]), .steps-complete .steps-item)::after {        background: CanvasText;      }    }  }  /* The words of a step: a title and an optional line under it. */  .steps-body {    display: grid;    gap: .0625rem;    min-width: 0;  }  /* One line, cut with an ellipsis where the step's room ends, so it never runs over the line to the next one. */  .steps-title {    min-width: 0;    margin: 0;    overflow: hidden;    font-weight: var(--font-weight-control);    text-overflow: ellipsis;    white-space: nowrap;  }  .steps-description {    margin: 0;    color: var(--color-text-muted);    font-size: .75rem;    font-weight: 400;    text-wrap: pretty;    overflow-wrap: anywhere;  }  /* Vertical: the marker stands on a column and the line runs down from it to the next marker. */  .steps-vertical .steps-item {    flex: none;    align-items: flex-start;    gap: .75rem;    padding-block-end: 1.25rem;    &:last-child {      padding-block-end: 0;    }    /* On the marker's middle, a half pixel back so the 1px line is centered as a timeline's and a trace's are. */    &:not(:last-child)::after {      position: absolute;      inset-block: calc(var(--steps-marker) + .25rem) .25rem;      inset-inline-start: calc(var(--steps-marker) / 2 - .5px);      flex: none;      width: 1px;      min-width: 0;      height: auto;    }  }  /* The first line stands on the middle of the marker, whether the title is alone or in a steps-body. */  .steps-vertical :is(.steps-body, .steps-item:not(:has(.steps-body)) .steps-title) {    padding-block-start: calc((var(--steps-marker) - 1lh) / 2);  }  .steps-vertical .steps-title {    white-space: normal;  }}