按鈕
凸起的控制項,懸停時微微抬升,按下時向內凹陷。
本頁內容
按鈕略微凸起,輪廓線寬半像素。指標懸停時,按鈕會抬高半像素,按下時則會沉入凹槽。即使色彩維持不變,也能從光影和深度辨識狀態。執行動作時,請將 .btn 加在 <button> 上。導覽連結若需要按鈕的外觀,則將它加在 <a> 上。
按鈕
<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 上呈珍珠白。每個畫面只用一次,留給畫面的主要動作。btn-quiet平時沒有可見的表面,互動時才顯現。適合用於工具列、頁首和排列緊密的項目列。btn-danger保留凸起的材質,並以危險狀態的文字色顯示標籤。btn-brand是唯一帶有色相的控制項,預設採用品牌靛藍,適合首頁的行動呼籲或升級等需要強調的動作。每個畫面最多使用一次。表面、邊緣和光暈都由--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。介面較緊湊時可用 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>分割按鈕的第二個按鈕通常用來開啟選單。加上 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 上使用 ink,obsidian 上使用 pearl。搭配 btn-danger 時,以危險色填滿按鈕,供使用者確認破壞性操作。搭配 btn 使用 |
btn-quiet | 適用於工具列、頁首和緊密排列的列,互動時才顯示背景搭配 btn 使用 |
btn-brand | 以 --color-brand 填色的控制項,每個檢視最多一個。搭配 btn 使用 |
btn-danger | 破壞性操作的標籤使用危險狀態的前景色搭配 btn 使用 |
btn-sm | 高度 32px,預設為 38px搭配 btn 使用 |
btn-lg | 高度 44px,預設為 38px搭配 btn 使用 |
btn-square | 容納單一圖示的方形按鈕,須提供無障礙名稱搭配 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 | 按鈕內圖示的大小 |