HTML5 (WHATWG Living Standard) 引入 100+ 新元素與屬性,確立「語意化、原生多媒體、離線應用、裝置存取」四大支柱。本文分類梳理核心新標籤、棄用對照、遷移策略,助你快速掌握現代 HTML 開發精髓。
| 元素 | 核心屬性 | 關鍵特性 |
<video> | src, controls, preload, poster, loop, muted, playsinline, width, height | 多 <source> 降級、<track> 字幕、MediaSource API 串流 |
<audio> | src, controls, preload, loop, muted | 音訊串流、Web Audio API 節點來源 |
<source> | src, type, media | 響應式格式選擇 (WebM/MP4/Ogg) |
<track> | kind (subtitles/captions/descriptions/chapters/metadata), srclang, label, default | 無障礙字幕、SEO 索引 |
<picture> | 響應式圖片容器 | 多 source (media/type/srcset) + 1 img 降級 |
| 類型/元素 | 用途 | 關鍵屬性/API |
input[type=email] | 電子郵件 | 自動驗證格式、行動鍵盤 @/.com |
input[type=url] | 網址 | 自動驗證協議、行動鍵盤 .com |
input[type=tel] | 電話 | 行動鍵盤數字鍵盤、無格式驗證 |
input[type=number] | 數值 | min, max, step, 微調鈕 |
input[type=range] | 滑桿 | min, max, step, orient |
input[type=date] | 日期選擇器 | min, max, step (天) |
input[type=time] | 時間選擇器 | step (秒, 預設 60) |
input[type=datetime-local] | 本地日期時間 | 無時區,ISO 8601 格式 |
input[type=month] | 年月 | — |
input[type=week] | 年週 | — |
input[type=color] | 顏色選擇器 | 回傳 #rrggbb |
input[type=search] | 搜尋框 | 清除鈕、語意化 |
<datalist> | 輸入建議清單 | id 配合 input[list] |
<output> | 計算結果顯示 | for 關聯輸入 id |
<progress> | 任務進度 | value, max, 不確定進度省略 value |
<meter> | 標量測量 | min, max, low, high, optimum |
| 驗證屬性 | — | required, pattern, minlength, maxlength, novalidate (form) |
| Constraint Validation API | JS 程式化驗證 | checkValidity(), reportValidity(), setCustomValidity(), validity 物件 |
| 棄用元素 | 替代方案 |
<font>, <basefont> | CSS font-family, font-size, color |
<center> | CSS text-align:center / margin:auto |
<strike>, <u> | CSS text-decoration: line-through/underline 或 <del>/<ins> |
<big>, <small> (表現用途) | CSS font-size / <small> 保留語意「側註」 |
<frame>, <frameset>, <noframes> | CSS Flex/Grid, <iframe>, SPA 路由 |
<acronym> | <abbr> |
<applet> | <object> / Web 技術 |
<isindex> | <input type="search"> |
<dir> | <ul> |
<listing>, <plaintext>, <xmp> | <pre><code> |
<marquee> | CSS Animation / JS |
<nobr> | CSS white-space: nowrap |
<tt> | <code>, <kbd>, <samp> 或 CSS font-family: monospace |
HTML5 不是「新增一堆標籤」,而是**重新定義網頁平台能力邊界**。掌握語意核心、善用原生 API、配合漸進增強策略,打造堅固、無障礙、高效能的現代 Web 體驗。