メニュー

アイコンのボタン

文字を置く場所がないときに、アイコンだけで操作を示すボタンです。名前は aria-label で必ず付けます。

見本で種類と状態を確かめる

種類は地のない quiet(既定)と、枠の付いた secondary の 2 つです。大きさは見た目 44 の既定と 36 の sm で、sm も押せる範囲は 44 あります。

種類と大きさ

押した状態

注目の予定に入っています

押していない状態

注目の予定に入っていません

コードを写す

HTML

<button class="mz-icon-button" type="button" aria-label="明細を編集する">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/></svg>
</button>
<button class="mz-icon-button" data-variant="secondary" type="button" aria-label="ほかの操作を開く">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>
</button>
<button class="mz-icon-button" data-size="sm" type="button" aria-label="お知らせを閉じる">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
<button class="mz-icon-button" data-variant="secondary" data-size="sm" type="button" aria-label="明細を削除する">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
</button>

<button class="mz-icon-button" type="button" aria-label="注目の予定に入れる" aria-pressed="true" data-toggle>
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"/></svg>
</button>

アイコンは Lucide の線のアイコン(20)を、stroke-width="1.5" で入れます。上の … には、使うアイコンの SVG の中身を入れます。

いつ使うか

  • 行の操作・閉じる・編集など、意味がアイコンで広く通じる操作に使います。
  • 文字で書ける場所があるなら、ボタンにアイコンと文字を並べます。
  • 入れる・外すを切り替える操作は aria-pressed で押した状態を持たせ、地を accent-soft にします。

読み上げとキーボードにどう応えるか

  • aria-label に操作の名前を動詞で書きます(「明細を編集する」)。ツールチップに頼りません。
  • アイコンの SVG には aria-hidden="true" を付け、名前は button だけが持ちます。
  • 押した状態は aria-pressed で伝わるので、名前は切り替えても変えません。

よい例と悪い例

よい例名前を操作の動詞で書く。読み上げでは「明細を削除する、ボタン」と伝わる
悪い例名前がアイコンの形(「ごみ箱」)だと、押すと何が起きるかが伝わらない

更新日

ページの一覧

索引を読み込んでいます。

メニュー