檔案
將單一檔案呈現為帶有名稱的獨立物件,可用於附件、上傳或下載。
本頁內容
檔案元件將一份文件呈現為一個獨立物件:小紙張上顯示副檔名,旁邊是檔名,下方以低調的一行文字列出檔案資訊,末端有一個操作控制項。元件採用平整的紙張外觀,因此在檔案拖放區下方或對話框內直向排列時,看起來就像一疊各自獨立的紙張。
檔案
<ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file"> <span class="file-page" aria-hidden="true">pdf</span> <div class="file-body"> <p class="file-name">Q3 infrastructure report.pdf</p> <p class="file-meta">2.4 MB · PDF document</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove Q3 infrastructure report.pdf"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </div> </li> <li class="file"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <div class="file-body"> <p class="file-name">moonstone-cover.png</p> <p class="file-meta">1,920 × 1,200 · 840 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove moonstone-cover.png"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </div> </li> <li class="file"> <span class="file-page" aria-hidden="true">csv</span> <div class="file-body"> <p class="file-name">members-export-2026-11.csv</p> <p class="file-meta">312 rows · 18 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove members-export-2026-11.csv"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </div> </li></ul>import XIcon from '@master/icons-react/native/16/soft/x'<ul className="flex flex-col gap-xs max-w(400) mx-auto"> <li className="file"> <span className="file-page" aria-hidden="true">pdf</span> <div className="file-body"> <p className="file-name">Q3 infrastructure report.pdf</p> <p className="file-meta">2.4 MB · PDF document</p> </div> <div className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Remove Q3 infrastructure report.pdf"> <XIcon className="icon" /> </button> </div> </li> <li className="file"> <img className="file-thumb" src="/demo/moonstone.svg" alt="" /> <div className="file-body"> <p className="file-name">moonstone-cover.png</p> <p className="file-meta">1,920 × 1,200 · 840 KB</p> </div> <div className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Remove moonstone-cover.png"> <XIcon className="icon" /> </button> </div> </li> <li className="file"> <span className="file-page" aria-hidden="true">csv</span> <div className="file-body"> <p className="file-name">members-export-2026-11.csv</p> <p className="file-meta">312 rows · 18 KB</p> </div> <div className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Remove members-export-2026-11.csv"> <XIcon className="icon" /> </button> </div> </li></ul><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file"> <span class="file-page" aria-hidden="true">pdf</span> <div class="file-body"> <p class="file-name">Q3 infrastructure report.pdf</p> <p class="file-meta">2.4 MB · PDF document</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove Q3 infrastructure report.pdf"> <XIcon class="icon" /> </button> </div> </li> <li class="file"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <div class="file-body"> <p class="file-name">moonstone-cover.png</p> <p class="file-meta">1,920 × 1,200 · 840 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove moonstone-cover.png"> <XIcon class="icon" /> </button> </div> </li> <li class="file"> <span class="file-page" aria-hidden="true">csv</span> <div class="file-body"> <p class="file-name">members-export-2026-11.csv</p> <p class="file-meta">312 rows · 18 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove members-export-2026-11.csv"> <XIcon class="icon" /> </button> </div> </li></ul><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file"> <span class="file-page" aria-hidden="true">pdf</span> <div class="file-body"> <p class="file-name">Q3 infrastructure report.pdf</p> <p class="file-meta">2.4 MB · PDF document</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove Q3 infrastructure report.pdf"> <XIcon class="icon" /> </button> </div> </li> <li class="file"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <div class="file-body"> <p class="file-name">moonstone-cover.png</p> <p class="file-meta">1,920 × 1,200 · 840 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove moonstone-cover.png"> <XIcon class="icon" /> </button> </div> </li> <li class="file"> <span class="file-page" aria-hidden="true">csv</span> <div class="file-body"> <p class="file-name">members-export-2026-11.csv</p> <p class="file-meta">312 rows · 18 KB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove members-export-2026-11.csv"> <XIcon class="icon" /> </button> </div> </li> </ul></template>#紙張圖示
file-page 是一張略微隆起的小紙張,尺寸為 28 × 36,底部顯示副檔名。輸入時可用任意大小寫,顯示時一律轉為大寫。副檔名請控制在 4 個字元以內。旁邊的檔名已包含相同資訊,因此請用 aria-hidden 對輔助技術隱藏紙張圖示。
折角由瀏覽器繪製。使用 corner-shape 時,紙張末端的上角會切成斜角,小方塊沿著斜角裁切後留下的部分就是折面。瀏覽器若不支援 corner-shape,紙張會顯示為四個圓角,沒有折角。
如果檔案是圖片,請將 file-thumb 套用在 <img> 上,以取代紙張圖示。
#上傳中
在檔案元件內放入帶有 progress file-progress 的原生 <progress>。整張紙就是進度條,從一側延伸到另一側,位於文字下方,並依上傳進度為紙張底色著色。填色在紙張邊角處會沿著外形收邊。未提供 value 時,進度未知,同色的色帶會在紙張上移動。
也請在 file-meta 中寫出進度,並在上傳期間以 aria-busy="true" 標記檔案。
上傳中
<ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">zip</span> <div class="file-body"> <p class="file-name">atlas-build-2026-11-11.zip</p> <p class="file-meta">Uploading · 64% of 182 MB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Cancel the upload of atlas-build-2026-11-11.zip"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </div> <progress class="progress file-progress" max="100" value="64" aria-label="Upload of atlas-build-2026-11-11.zip"> 64% </progress> </li> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">mp4</span> <div class="file-body"> <p class="file-name">onboarding-walkthrough.mp4</p> <p class="file-meta">Scanning for viruses…</p> </div> <progress class="progress file-progress" aria-label="Scan of onboarding-walkthrough.mp4"></progress> </li></ul>import XIcon from '@master/icons-react/native/16/soft/x'<ul className="flex flex-col gap-xs max-w(400) mx-auto"> <li className="file" aria-busy="true"> <span className="file-page" aria-hidden="true">zip</span> <div className="file-body"> <p className="file-name">atlas-build-2026-11-11.zip</p> <p className="file-meta">Uploading · 64% of 182 MB</p> </div> <div className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Cancel the upload of atlas-build-2026-11-11.zip"> <XIcon className="icon" /> </button> </div> <progress className="progress file-progress" max="100" value="64" aria-label="Upload of atlas-build-2026-11-11.zip"> 64% </progress> </li> <li className="file" aria-busy="true"> <span className="file-page" aria-hidden="true">mp4</span> <div className="file-body"> <p className="file-name">onboarding-walkthrough.mp4</p> <p className="file-meta">Scanning for viruses…</p> </div> <progress className="progress file-progress" aria-label="Scan of onboarding-walkthrough.mp4"></progress> </li></ul><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">zip</span> <div class="file-body"> <p class="file-name">atlas-build-2026-11-11.zip</p> <p class="file-meta">Uploading · 64% of 182 MB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Cancel the upload of atlas-build-2026-11-11.zip"> <XIcon class="icon" /> </button> </div> <progress class="progress file-progress" max="100" value="64" aria-label="Upload of atlas-build-2026-11-11.zip"> 64% </progress> </li> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">mp4</span> <div class="file-body"> <p class="file-name">onboarding-walkthrough.mp4</p> <p class="file-meta">Scanning for viruses…</p> </div> <progress class="progress file-progress" aria-label="Scan of onboarding-walkthrough.mp4"></progress> </li></ul><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <ul class="flex flex-col gap-xs max-w(400) mx-auto"> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">zip</span> <div class="file-body"> <p class="file-name">atlas-build-2026-11-11.zip</p> <p class="file-meta">Uploading · 64% of 182 MB</p> </div> <div class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Cancel the upload of atlas-build-2026-11-11.zip"> <XIcon class="icon" /> </button> </div> <progress class="progress file-progress" max="100" value="64" aria-label="Upload of atlas-build-2026-11-11.zip"> 64% </progress> </li> <li class="file" aria-busy="true"> <span class="file-page" aria-hidden="true">mp4</span> <div class="file-body"> <p class="file-name">onboarding-walkthrough.mp4</p> <p class="file-meta">Scanning for viruses…</p> </div> <progress class="progress file-progress" aria-label="Scan of onboarding-walkthrough.mp4"></progress> </li> </ul></template>#失敗
file-failed 會為檔案套用危險狀態的外框,並將 file-meta 的文字改為危險狀態的顏色。請在這裡說明失敗原因,並在末端提供後續操作。ARIA 沒有可標記清單項目失敗的屬性,因此這個狀態用類別設定,並透過文字傳達。在這段文字上加上 role="alert",即可在使用者瀏覽頁面時宣告當下發生的失敗。
失敗
<div class="file file-failed max-w(400) mx-auto"> <span class="file-page" aria-hidden="true">mov</span> <div class="file-body"> <p class="file-name">walkthrough-final-v2.mov</p> <p class="file-meta" role="alert">Larger than the 100 MB limit</p> </div> <div class="file-end"><button type="button" class="btn btn-sm">Replace</button></div></div><div className="file file-failed max-w(400) mx-auto"> <span className="file-page" aria-hidden="true">mov</span> <div className="file-body"> <p className="file-name">walkthrough-final-v2.mov</p> <p className="file-meta" role="alert">Larger than the 100 MB limit</p> </div> <div className="file-end"><button type="button" className="btn btn-sm">Replace</button></div></div><div class="file file-failed max-w(400) mx-auto"> <span class="file-page" aria-hidden="true">mov</span> <div class="file-body"> <p class="file-name">walkthrough-final-v2.mov</p> <p class="file-meta" role="alert">Larger than the 100 MB limit</p> </div> <div class="file-end"><button type="button" class="btn btn-sm">Replace</button></div></div><template> <div class="file file-failed max-w(400) mx-auto"> <span class="file-page" aria-hidden="true">mov</span> <div class="file-body"> <p class="file-name">walkthrough-final-v2.mov</p> <p class="file-meta" role="alert">Larger than the 100 MB limit</p> </div> <div class="file-end"><button type="button" class="btn btn-sm">Replace</button></div> </div></template>#精簡版
file-sm 採單行版面配置,高 32px,寬度隨檔名而定,適合用於訊息編輯器上方的附件,或在某一列中提及的檔案。它和小型按鈕等高,兩者可以排在同一列。紙張圖示太小,無法顯示副檔名,因此由旁邊的檔名與檔案資訊呈現。無論使用哪種指標輸入方式,末端控制項的尺寸都是 24px,並從紙張邊緣向內縮 4px。在觸控螢幕上,點按範圍會以控制項為中心擴大至 44px。
精簡版
<form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="file file-sm"> <span class="file-page" aria-hidden="true"></span> <span class="file-body"> <span class="file-name">report.pdf</span><span class="file-meta">2.4 MB</span> </span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove report.pdf"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> </span> <span class="file file-sm"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <span class="file-body"><span class="file-name">cover.png</span></span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove cover.png"> <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 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> </span> </div> <textarea class="composer-field" rows="1" placeholder="Add a note about these files" aria-label="Message"></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button type="submit" class="btn btn-primary btn-sm">Send</button> </div> </div></form>import XIcon from '@master/icons-react/native/16/soft/x'<form className="composer max-w(480) mx-auto"> <div className="composer-attachments"> <span className="file file-sm"> <span className="file-page" aria-hidden="true"></span> <span className="file-body"> <span className="file-name">report.pdf</span><span className="file-meta">2.4 MB</span> </span> <span className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Remove report.pdf"> <XIcon className="icon" /> </button> </span> </span> <span className="file file-sm"> <img className="file-thumb" src="/demo/moonstone.svg" alt="" /> <span className="file-body"><span className="file-name">cover.png</span></span> <span className="file-end"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Remove cover.png"> <XIcon className="icon" /> </button> </span> </span> </div> <textarea className="composer-field" rows={1} placeholder="Add a note about these files" aria-label="Message">{``}</textarea> <div className="composer-toolbar"> <div className="composer-end"> <button type="submit" className="btn btn-primary btn-sm">Send</button> </div> </div></form><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="file file-sm"> <span class="file-page" aria-hidden="true"></span> <span class="file-body"> <span class="file-name">report.pdf</span><span class="file-meta">2.4 MB</span> </span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove report.pdf"> <XIcon class="icon" /> </button> </span> </span> <span class="file file-sm"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <span class="file-body"><span class="file-name">cover.png</span></span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove cover.png"> <XIcon class="icon" /> </button> </span> </span> </div> <textarea class="composer-field" rows="1" placeholder="Add a note about these files" aria-label="Message"></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button type="submit" class="btn btn-primary btn-sm">Send</button> </div> </div></form><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="file file-sm"> <span class="file-page" aria-hidden="true"></span> <span class="file-body"> <span class="file-name">report.pdf</span><span class="file-meta">2.4 MB</span> </span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove report.pdf"> <XIcon class="icon" /> </button> </span> </span> <span class="file file-sm"> <img class="file-thumb" src="/demo/moonstone.svg" alt> <span class="file-body"><span class="file-name">cover.png</span></span> <span class="file-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove cover.png"> <XIcon class="icon" /> </button> </span> </span> </div> <textarea class="composer-field" rows="1" placeholder="Add a note about these files" aria-label="Message"></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button type="submit" class="btn btn-primary btn-sm">Send</button> </div> </div> </form></template>#可開啟的檔案
整個檔案元件若是連結或按鈕,請加上 file-interactive。它會像按鈕一樣,平時略微隆起,指標移入時抬高,按下時下沉。連結內的各個部分請使用 <span>。
可開啟的檔案
<div class="grid grid-cols(2) gap-sm max-w(520) mx-auto"> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">docx</span> <span class="file-body"> <span class="file-name">Master services agreement.docx</span> <span class="file-meta">48 KB · Download</span> </span> </a> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">xlsx</span> <span class="file-body"> <span class="file-name">Pricing schedule.xlsx</span> <span class="file-meta">22 KB · Download</span> </span> </a></div><div className="grid grid-cols(2) gap-sm max-w(520) mx-auto"> <a className="file file-interactive" href="#" download> <span className="file-page" aria-hidden="true">docx</span> <span className="file-body"> <span className="file-name">Master services agreement.docx</span> <span className="file-meta">48 KB · Download</span> </span> </a> <a className="file file-interactive" href="#" download> <span className="file-page" aria-hidden="true">xlsx</span> <span className="file-body"> <span className="file-name">Pricing schedule.xlsx</span> <span className="file-meta">22 KB · Download</span> </span> </a></div><div class="grid grid-cols(2) gap-sm max-w(520) mx-auto"> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">docx</span> <span class="file-body"> <span class="file-name">Master services agreement.docx</span> <span class="file-meta">48 KB · Download</span> </span> </a> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">xlsx</span> <span class="file-body"> <span class="file-name">Pricing schedule.xlsx</span> <span class="file-meta">22 KB · Download</span> </span> </a></div><template> <div class="grid grid-cols(2) gap-sm max-w(520) mx-auto"> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">docx</span> <span class="file-body"> <span class="file-name">Master services agreement.docx</span> <span class="file-meta">48 KB · Download</span> </span> </a> <a class="file file-interactive" href="#" download> <span class="file-page" aria-hidden="true">xlsx</span> <span class="file-body"> <span class="file-name">Pricing schedule.xlsx</span> <span class="file-meta">22 KB · Download</span> </span> </a> </div></template>#無障礙
- 有多個檔案時,請用
<ul>建立清單,並在每個<li>上加上file。 - 控制項的名稱應指出操作對象,例如將「移除」寫成「移除 report.pdf」。
- 請為
<progress>加上標籤,並在文字中保留百分比。底色只是將進度以視覺方式呈現。 - 過長的檔名會從尾端截斷。如果尾端資訊很重要,例如副檔名,請在
title中提供完整檔名。
#類別
| 類別 | 說明 |
|---|---|
file | 容納文件圖示、文字與控制項的平面面板。 |
file-failed | 上傳失敗時,外框和 file-meta 使用危險狀態的前景色,並在 file-meta 說明失敗原因。搭配 file 使用 |
file-sm | 單列高 32px,與小型按鈕同高,寬度依檔名而定。文件圖示較小,因此省略圖示上的副檔名。內嵌按鈕大小為 24px,內縮 4px。搭配 file 使用 |
file-interactive | 整個檔案項目都是連結或按鈕。平時呈凸起狀,指標懸停時會抬高,按下時會下沉。搭配 file 使用 |
file-page | 28 × 36 的小型文件圖示,底部以大寫字母顯示副檔名 |
file-thumb | 若檔案是圖片,就以該圖片取代文件圖示。 |
file-body | 名稱,以及下方一行摘要資訊。 |
file-name | 檔名顯示為單行,超出時在末尾加上省略號 |
file-meta | 檔案大小、類型、上傳進度或失敗原因 |
file-end | 末端的控制項可用來移除、重試或下載 |
file-progress | 在 progress 元素上套用 progress 時,進度條位於文字底層,並依上傳進度為面板著色 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--file-padding | .625rem | 面板內距,小型檔案項目為 .25rem。 |
--file-radius | var(--radius-control-lg) | 面板圓角。小型檔案使用 var(--radius-control-sm)。 |
--file-page-width | 1.75rem | 文件圖示的寬度,小型檔案項目為 1rem。 |
--file-page-height | 2.25rem | 文件圖示的高度,小型檔案項目為 1.25rem。 |
--file-fold | .5625rem | 摺角的大小,小型檔案為 .3125rem |
#相關元件
- 檔案拖放區提供寬大的區域供使用者選取或拖放檔案,建立在原生檔案輸入欄位上,不需要腳本也能運作。
- 訊息編輯器用來撰寫訊息或提示詞,上方是會自動增高的欄位,下方是一排工具。
- 清單將項目逐列排列,每列可放置媒體、文字和尾端內容。