| type | UI 外觀 | 資料型別 | 驗證 | 關鍵屬性 |
|---|---|---|---|---|
| hidden | 不顯示 | string | 無 | value |
| text | 單行文字 | string | pattern, maxlength | list, placeholder, autocomplete |
| search | 搜尋框 (含清除鈕) | string | 同 text | 同 text |
| tel | 電話 (無內建驗證) | string | pattern | autocomplete="tel" |
| url | 網址 | URL string | URL 格式 | autocomplete="url" |
| 郵件 | email string | Email 格式 | multiple, autocomplete="email" | |
| password | 遮罩文字 | string | pattern, minlength | autocomplete="current-password/new-password" |
| date | 日期選擇器 | YYYY-MM-DD | min/max/step | readonly 建議搭配 |
| time | 時間選擇器 | HH:MM[:SS] | min/max/step | |
| datetime-local | 日期時間 (無時區) | YYYY-MM-DDTHH:MM | min/max/step | |
| month | 年月選擇 | YYYY-MM | min/max/step | |
| week | 年週選擇 | YYYY-Www | min/max/step | |
| number | 數字步進器 | number | min/max/step | inputmode="numeric" |
| range | 滑桿 | number | min/max/step | orient="vertical" (非標準) |
| color | 顏色選擇器 | #rrggbb | 無 | list 可預設調色盤 |
| checkbox | 複選框 | boolean | required | value (提交值), indeterminate (JS) |
| radio | 單選鈕 | string | required (群組) | name 相同者互斥 |
| file | 檔案選擇 | FileList | accept, multiple | capture="user/environment" (行動裝置相機) |
| submit | 提交按鈕 | - | - | value=按鈕文字, formaction/formmethod 覆蓋 form |
| image | 圖片提交 | - | - | src, alt, width, height |
| reset | 重置按鈕 | - | - | value=按鈕文字 |
| button | 無預設行為按鈕 | - | - | 配合 JS 事件 |
name:提交鍵名 (必填,除 submit/image/button 外)。value:初始/提交值。disabled:禁用 (不提交、不可聚焦、灰色)。readonly:唯讀 (可聚焦、可複製、會提交)。required:必填驗證。autofocus:自動聚焦 (每頁限一)。autocomplete:瀏覽器自動填入策略。form:關聯非祖先 form (id)。list:關聯 <datalist> (id)。placeholder:提示文字 (非 label 替代品)。aria-label/aria-labelledby:無障礙名稱 (無視覺 label 時)。const input = document.querySelector('input[required]');
input.checkValidity(); // true/false
input.reportValidity(); // 顯示瀏覽器原生錯誤泡泡
input.setCustomValidity('自訂錯誤訊息'); // 設定自訂錯誤
input.validity; // ValidityState 物件 {valueMissing, typeMismatch, patternMismatch, tooLong, tooShort, rangeUnderflow, rangeOverflow, stepMismatch, badInput, customError}
<label for="id">標籤</label> <input id="id"><label>標籤 <input></label><input aria-label="標籤"> 或 aria-labelledby="id" (無視覺 label 時)。正確使用 <label> 能讓螢幕閱讀器朗讀、點擊放大點擊區域、瀏覽器自動填入正確識別欄位。