ボタン
面からわずかに浮いた操作要素です。ポインターを重ねるとさらに浮き上がり、押すと沈み込みます。
このページの内容
ボタンは、0.5px の輪郭を持ち、背景面からわずかに浮いた小さなシートです。ポインターを重ねると 0.5px 浮き上がり、押すとくぼみに沈みます。明暗と奥行きの変化で状態がわかるため、色の違いに頼りません。操作には <button>、ボタンの見た目にしたいナビゲーションには <a> を使い、それぞれにクラス .btn を指定します。
ボタン
<button type="button" class="btn">Cancel</button><button type="button" class="btn btn-primary">Save changes</button><> <button type="button" className="btn">Cancel</button> <button type="button" className="btn btn-primary">Save changes</button></><button type="button" class="btn">Cancel</button><button type="button" class="btn btn-primary">Save changes</button><template> <button type="button" class="btn">Cancel</button> <button type="button" class="btn btn-primary">Save changes</button></template>#バリエーション
既定のボタンは moonstone です。操作の重要度に合わせてバリエーションを選びます。
btn-primaryは、moonstone の面にインク色、obsidian の面にパール色を使います。そのビューの主目的となる操作に、ビューごとに 1 つ使います。btn-quietは、操作するまでボタン面の質感が現れません。ツールバー、ヘッダー、項目が密に並ぶ行に使います。btn-dangerは浮き上がった面の質感を保ち、ラベルに危険を示す文字色を使います。btn-brandは、ブランドのインディゴを使う唯一の有彩色のボタンです。ホームページで行動を促すボタンや、アップグレードなど、特に目立たせたい操作に使います。1 つのビューにつき最大 1 つです。ボタン面、縁、光彩の色は--color-brandから合成するため、ブランドカラーに連動します。
バリエーション
<button type="button" class="btn">Default</button><button type="button" class="btn btn-primary">Primary</button><button type="button" class="btn btn-quiet">Quiet</button><button type="button" class="btn btn-danger">Delete</button><button type="button" class="btn btn-brand">Get started</button><> <button type="button" className="btn">Default</button> <button type="button" className="btn btn-primary">Primary</button> <button type="button" className="btn btn-quiet">Quiet</button> <button type="button" className="btn btn-danger">Delete</button> <button type="button" className="btn btn-brand">Get started</button></><button type="button" class="btn">Default</button><button type="button" class="btn btn-primary">Primary</button><button type="button" class="btn btn-quiet">Quiet</button><button type="button" class="btn btn-danger">Delete</button><button type="button" class="btn btn-brand">Get started</button><template> <button type="button" class="btn">Default</button> <button type="button" class="btn btn-primary">Primary</button> <button type="button" class="btn btn-quiet">Quiet</button> <button type="button" class="btn btn-danger">Delete</button> <button type="button" class="btn btn-brand">Get started</button></template>#破壊的な操作
btn-danger 単体では、浮き上がったボタンのラベルに危険を示す文字色を使う、控えめな表示になります。ほかの操作に交じって削除ボタンを置く場合などに使います。btn-primary と組み合わせると、ブランドボタンをブランドカラーで塗りつぶすのと同じように、危険を示す色で塗りつぶした確認ボタンになります。塗りつぶしは ダイアログ 内の確定ボタンなど、最終段階に限って使い、ラベルには実行する操作を明記します。
破壊的な操作
<button type="button" class="btn btn-danger">Delete</button><button type="button" class="btn btn-primary btn-danger">Delete project</button><button type="button" class="btn btn-primary btn-danger" disabled>Delete project</button><> <button type="button" className="btn btn-danger">Delete</button> <button type="button" className="btn btn-primary btn-danger">Delete project</button> <button type="button" className="btn btn-primary btn-danger" disabled>Delete project</button></><button type="button" class="btn btn-danger">Delete</button><button type="button" class="btn btn-primary btn-danger">Delete project</button><button type="button" class="btn btn-primary btn-danger" disabled>Delete project</button><template> <button type="button" class="btn btn-danger">Delete</button> <button type="button" class="btn btn-primary btn-danger">Delete project</button> <button type="button" class="btn btn-primary btn-danger" disabled>Delete project</button></template>#サイズ
高さは既定で 38px です。要素が密に並ぶ UI では 32px、目立たせたい操作では 44px を使います。パディング、ラベルの文字サイズ、アイコンのサイズ、角丸の半径も連動して変わります。タッチスクリーンでも、どのサイズも高さと見た目は変わりません。ボタンの見えないタッチ領域は 44px まで広がるため、同じ行に並べたボタンとフィールドの見た目の高さはそろったままです。
サイズ
<button type="button" class="btn btn-sm">Small</button><button type="button" class="btn">Medium</button><button type="button" class="btn btn-lg">Large</button><> <button type="button" className="btn btn-sm">Small</button> <button type="button" className="btn">Medium</button> <button type="button" className="btn btn-lg">Large</button></><button type="button" class="btn btn-sm">Small</button><button type="button" class="btn">Medium</button><button type="button" class="btn btn-lg">Large</button><template> <button type="button" class="btn btn-sm">Small</button> <button type="button" class="btn">Medium</button> <button type="button" class="btn btn-lg">Large</button></template>#アイコン付き
アイコン自体に icon を指定します。アイコンのサイズはボタン側で決まり、既定は 16px、小サイズは 14px、大サイズは 18px で、線幅は図案のものを保ちます。btn-square を指定すると正方形のボタンになります。aria-label でアクセシブルな名前を付けます。
アイコン付き
<button type="button" class="btn btn-primary"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> New project</button><button type="button" class="btn btn-square" aria-label="Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" /> </svg></button><button type="button" class="btn btn-quiet btn-square" aria-label="More"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.5" cy="8" r="1.05" fill="currentColor" stroke="none" /><circle cx="8" cy="8" r="1.05" fill="currentColor" stroke="none" /><circle cx="12.5" cy="8" r="1.05" fill="currentColor" stroke="none" /> </svg></button>import PlusIcon from '@master/icons-react/native/16/soft/plus'import SearchIcon from '@master/icons-react/native/16/soft/search'import MoreHorizontalIcon from '@master/icons-react/native/16/soft/more-horizontal'<> <button type="button" className="btn btn-primary"> <PlusIcon className="icon" /> New project </button> <button type="button" className="btn btn-square" aria-label="Search"> <SearchIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-square" aria-label="More"> <MoreHorizontalIcon className="icon" /> </button></><script> import PlusIcon from '@master/icons-svelte/native/16/soft/plus' import SearchIcon from '@master/icons-svelte/native/16/soft/search' import MoreHorizontalIcon from '@master/icons-svelte/native/16/soft/more-horizontal'</script><button type="button" class="btn btn-primary"><PlusIcon class="icon" /> New project</button><button type="button" class="btn btn-square" aria-label="Search"> <SearchIcon class="icon" /></button><button type="button" class="btn btn-quiet btn-square" aria-label="More"> <MoreHorizontalIcon class="icon" /></button><script setup>import PlusIcon from '@master/icons-vue/native/16/soft/plus'import SearchIcon from '@master/icons-vue/native/16/soft/search'import MoreHorizontalIcon from '@master/icons-vue/native/16/soft/more-horizontal'</script><template> <button type="button" class="btn btn-primary"><PlusIcon class="icon" /> New project</button> <button type="button" class="btn btn-square" aria-label="Search"> <SearchIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-square" aria-label="More"> <MoreHorizontalIcon class="icon" /> </button></template>#ピル型
btn-pill はボタンの両端を完全に丸めます。直線の端に比べて窮屈に見えやすいため、インライン方向の余白を少し増やします。
ピル型
<button type="button" class="btn btn-pill">Follow</button><button type="button" class="btn btn-primary btn-pill">Subscribe</button><> <button type="button" className="btn btn-pill">Follow</button> <button type="button" className="btn btn-primary btn-pill">Subscribe</button></><button type="button" class="btn btn-pill">Follow</button><button type="button" class="btn btn-primary btn-pill">Subscribe</button><template> <button type="button" class="btn btn-pill">Follow</button> <button type="button" class="btn btn-primary btn-pill">Subscribe</button></template>#トグル
控えめなボタンに aria-pressed="true" を指定すると、くぼみに沈んだ状態を保ちます。この属性は独自のスクリプトで更新します。直後に置いた メニュー や ポップオーバー が開いている間も、スクリプトなしで沈んだ状態を保ちます。
トグル
<button type="button" class="btn btn-quiet btn-square" aria-label="Bold" aria-pressed="true"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4.6667 3H8.3333C12.3333 3 12.3333 7.6667 8.3333 7.6667H4.6667M4.6667 3V13H9C13.3333 13 13.3333 7.6667 9 7.6667" /> </svg></button><button type="button" class="btn btn-quiet btn-square" aria-label="Italic" aria-pressed="false"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6.6667 3L12.6667 3" /><path d="M3.3333 13L9.3333 13" /><path d="M9.6667 3L6.3333 13" stroke-linecap="butt" /> </svg></button>import BoldIcon from '@master/icons-react/native/16/soft/bold'import ItalicIcon from '@master/icons-react/native/16/soft/italic'<> <button type="button" className="btn btn-quiet btn-square" aria-label="Bold" aria-pressed="true"> <BoldIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-square" aria-label="Italic" aria-pressed="false"> <ItalicIcon className="icon" /> </button></><script> import BoldIcon from '@master/icons-svelte/native/16/soft/bold' import ItalicIcon from '@master/icons-svelte/native/16/soft/italic'</script><button type="button" class="btn btn-quiet btn-square" aria-label="Bold" aria-pressed="true"> <BoldIcon class="icon" /></button><button type="button" class="btn btn-quiet btn-square" aria-label="Italic" aria-pressed="false"> <ItalicIcon class="icon" /></button><script setup>import BoldIcon from '@master/icons-vue/native/16/soft/bold'import ItalicIcon from '@master/icons-vue/native/16/soft/italic'</script><template> <button type="button" class="btn btn-quiet btn-square" aria-label="Bold" aria-pressed="true"> <BoldIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-square" aria-label="Italic" aria-pressed="false"> <ItalicIcon class="icon" /> </button></template>#ボタングループ
btn-group は関連する操作を一つの外形にまとめます。各ボタンは固有の質感を保ち、隣り合う角は直角になり、輪郭が重なって一本の境界線になります。グループ内ではボタンが個別に浮き上がらないため、全体の形が保たれます。グループには role="group" とラベルを指定します。
ボタングループ
<div class="btn-group" role="group" aria-label="History"> <button type="button" class="btn">Undo</button> <button type="button" class="btn">Redo</button></div><div class="btn-group" role="group" aria-label="Deploy"> <button type="button" class="btn btn-primary">Deploy</button> <button type="button" class="btn btn-primary btn-square" aria-label="Deploy options"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /> </svg> </button></div>import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'<> <div className="btn-group" role="group" aria-label="History"> <button type="button" className="btn">Undo</button> <button type="button" className="btn">Redo</button> </div> <div className="btn-group" role="group" aria-label="Deploy"> <button type="button" className="btn btn-primary">Deploy</button> <button type="button" className="btn btn-primary btn-square" aria-label="Deploy options"> <ChevronDownIcon className="icon" /> </button> </div></><script> import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><div class="btn-group" role="group" aria-label="History"> <button type="button" class="btn">Undo</button> <button type="button" class="btn">Redo</button></div><div class="btn-group" role="group" aria-label="Deploy"> <button type="button" class="btn btn-primary">Deploy</button> <button type="button" class="btn btn-primary btn-square" aria-label="Deploy options"> <ChevronDownIcon class="icon" /> </button></div><script setup>import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'</script><template> <div class="btn-group" role="group" aria-label="History"> <button type="button" class="btn">Undo</button> <button type="button" class="btn">Redo</button> </div> <div class="btn-group" role="group" aria-label="Deploy"> <button type="button" class="btn btn-primary">Deploy</button> <button type="button" class="btn btn-primary btn-square" aria-label="Deploy options"> <ChevronDownIcon class="icon" /> </button> </div></template>分割ボタンの 2 つ目のボタンは、通常 メニュー を開きます。popovertarget を追加すると、メニューがそのボタンに接する位置に自動で配置されます。
#ページネーション
控えめな正方形のボタンを横に並べて、各ページへのリンクを作ります。現在のページには aria-current="page" を指定し、オンのトグルと同じように、くぼみに沈んだ状態を保ちます。
ページネーション
<nav class="flex items-center gap(2)" aria-label="Pagination"> <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /> </svg> </a> <a class="btn btn-quiet btn-square btn-sm" href="#page-1">1</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-current="page">2</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3">3</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /> </svg> </a></nav>import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'<nav className="flex items-center gap(2)" aria-label="Pagination"> <a className="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page"> <ChevronLeftIcon className="icon" /> </a> <a className="btn btn-quiet btn-square btn-sm" href="#page-1">1</a> <a className="btn btn-quiet btn-square btn-sm" href="#page-2" aria-current="page">2</a> <a className="btn btn-quiet btn-square btn-sm" href="#page-3">3</a> <a className="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page"> <ChevronRightIcon className="icon" /> </a></nav><script> import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left' import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'</script><nav class="flex items-center gap(2)" aria-label="Pagination"> <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page"> <ChevronLeftIcon class="icon" /> </a> <a class="btn btn-quiet btn-square btn-sm" href="#page-1">1</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-current="page">2</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3">3</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page"> <ChevronRightIcon class="icon" /> </a></nav><script setup>import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'</script><template> <nav class="flex items-center gap(2)" aria-label="Pagination"> <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page"> <ChevronLeftIcon class="icon" /> </a> <a class="btn btn-quiet btn-square btn-sm" href="#page-1">1</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-current="page">2</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3">3</a> <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page"> <ChevronRightIcon class="icon" /> </a> </nav></template>#処理中
処理中は aria-busy="true" を設定します。ボタンはラベルと質感を保ち、ポインターを重ねても浮き上がらず、アイコンと同じサイズのインライン スピナー を表示します。ラベルは進行中の処理を伝える文言に変え、ハンドラーでは処理中の再操作を無視します。
処理中
<button type="button" class="btn" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Saving…</button><button type="button" class="btn btn-primary" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Publishing…</button><> <button type="button" className="btn" aria-busy="true"> <span className="spinner spinner-inline" aria-hidden="true"></span> Saving… </button> <button type="button" className="btn btn-primary" aria-busy="true"> <span className="spinner spinner-inline" aria-hidden="true"></span> Publishing… </button></><button type="button" class="btn" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Saving…</button><button type="button" class="btn btn-primary" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Publishing…</button><template> <button type="button" class="btn" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Saving… </button> <button type="button" class="btn btn-primary" aria-busy="true"> <span class="spinner spinner-inline" aria-hidden="true"></span> Publishing… </button></template>#無効
無効なボタンは背景面に沈み、平らなくぼみと無効状態の文字色で表示されます。リンク自体には無効化の機能がないため、aria-disabled="true" を指定し、href を削除します。無効にした理由が明らかでない場合は、ボタンの隣にテキストで示し、aria-describedby で関連付けます。無効なボタンに付けたツールチップには、キーボードでも指でも到達できません。
無効
<div class="flex flex-col items-center gap-xs"> <div class="flex flex-wrap justify-center gap-sm"> <button type="button" class="btn" disabled>Default</button> <button type="button" class="btn btn-primary" disabled aria-describedby="publish-reason"> Publish </button> </div> <p class="m(0) text-sm fg-text-muted" id="publish-reason">Add a title before you publish.</p></div><div className="flex flex-col items-center gap-xs"> <div className="flex flex-wrap justify-center gap-sm"> <button type="button" className="btn" disabled>Default</button> <button type="button" className="btn btn-primary" disabled aria-describedby="publish-reason"> Publish </button> </div> <p className="m(0) text-sm fg-text-muted" id="publish-reason">Add a title before you publish.</p></div><div class="flex flex-col items-center gap-xs"> <div class="flex flex-wrap justify-center gap-sm"> <button type="button" class="btn" disabled>Default</button> <button type="button" class="btn btn-primary" disabled aria-describedby="publish-reason"> Publish </button> </div> <p class="m(0) text-sm fg-text-muted" id="publish-reason">Add a title before you publish.</p></div><template> <div class="flex flex-col items-center gap-xs"> <div class="flex flex-wrap justify-center gap-sm"> <button type="button" class="btn" disabled>Default</button> <button type="button" class="btn btn-primary" disabled aria-describedby="publish-reason"> Publish </button> </div> <p class="m(0) text-sm fg-text-muted" id="publish-reason">Add a title before you publish.</p> </div></template>#個別のボタンを調整する
utilities レイヤーは components の後にあるため、ユーティリティがコンポーネントのスタイルより優先されます。
全幅
<button type="button" class="btn btn-primary btn-lg w-full">Continue</button><button type="button" className="btn btn-primary btn-lg w-full">Continue</button><button type="button" class="btn btn-primary btn-lg w-full">Continue</button><template> <button type="button" class="btn btn-primary btn-lg w-full">Continue</button></template>#クラス
| クラス | 説明 |
|---|---|
btn | 立体感のある基本ボタン |
btn-primary | moonstone地にインク色、obsidian地にパール色を使う、ビューの主要アクションです。btn-danger を指定すると、破壊的な操作の確認用に危険を示す色で塗りつぶされます。btn と併用します |
btn-quiet | 操作時に表面の質感が現れます。ツールバー、ヘッダー、要素が密に並ぶ行に使います。btn と併用します |
btn-brand | --color-brand で塗りつぶす有彩色のコントロールです。1 ビューにつき最大 1 つです。btn と併用します |
btn-danger | 破壊的な操作のラベルを、危険を示すインク色で表示します。btn と併用します |
btn-sm | 高さは 32px です。既定は 38px です。btn と併用します |
btn-lg | 高さは 44px です。既定は 38px です。btn と併用します |
btn-square | アイコンを 1 つ配置する正方形のボタンです。アクセシブルな名前が必要です。btn と併用します |
btn-pill | 両端を完全に丸めた形状btn と併用します |
btn-hang-start | 輪郭のないバーやヘッダーの先頭にある quiet ボタンに付ける。ボタンの枠がパディングにはみ出し、グリフがコンテンツの開始端にそろうbtn と併用します |
btn-hang-end | 末尾での同じ指定。グリフがコンテンツの終了端にそろうbtn と併用します |
btn-group | 複数のボタンを一体の形状にまとめるコンテナー |
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--btn-height | 2.375rem | ブロック方向の最小サイズ |
--btn-padding-x | 1rem | インライン方向のパディング |
--btn-gap | .5rem | アイコンとラベルの間隔 |
--btn-font-size | .84375rem | ラベルのサイズ |
--btn-radius | var(--radius-control) | 角の半径は 10px です。小サイズのボタンは 8px、大サイズのボタンは 12px です。 |
--icon-size | 1rem | ボタン内のアイコンのサイズ |