HTML5 強調語義化:標籤表達「內容含義」,樣式交由 CSS 控制。舊版表現層標籤(<font>, <b>, <i>, <u>, <s>, <center> 等)雖仍被瀏覽器支持,但不推薦在新項目使用。
| 舊標籤(表現) | HTML5 語義標籤 | 含義 | 默認樣式 | CSS 替代 |
|---|---|---|---|---|
<b> | <strong> | 重要、嚴肅、警告 | 粗體 | font-weight: bold |
<i> | <em> | 強調、語氣變化 | 斜體 | font-style: italic |
<u> | <ins> / <mark> | 插入內容 / 高亮標記 | 下劃線 | text-decoration: underline / background: yellow |
<s>/<strike> | <del> | 刪除、不再準確 | 刪除線 | text-decoration: line-through |
<font size="" color="" face=""> | CSS | 字體大小/顏色/字體族 | — | font-size, color, font-family |
<center> | CSS | 水平居中 | 居中 | text-align: center / Flex/Grid |
<big> | CSS | 放大字體 | 大號 | font-size: larger |
<small> | <small> (保留) | 側註、小字、免責聲明 | 小字 | font-size: smaller |
<tt> | <code>/<kbd>/<samp> | 代碼/鍵盤輸入/輸出樣本 | 等寬 | font-family: monospace |
<abbr title="HyperText Markup Language">HTML</abbr>:縮寫,滑鼠懸停顯示全稱。<cite>:引用作品標題(書名、電影、論文)。<q>:短行內引用,瀏覽器自動加引號(可用 CSS quotes 自定義)。<blockquote cite="url">:長塊級引用,可註明來源。<time datetime="2024-01-15">1月15日</time>:機器可讀時間。<data value="12345">產品編號</data>:機器可讀數據。/* 統一文本語義標籤樣式,避免瀏覽器默認差異 */
strong, b { font-weight: 700; }
em, i { font-style: italic; }
mark { background: #fff3cd; padding: 0.1em 0.2em; }
del, s, strike { text-decoration: line-through; }
ins, u { text-decoration: underline; }
code, kbd, samp, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
small { font-size: 0.875em; color: #666; }
sub, sup { font-size: 0.75em; line-height: 0; position: relative; vertical-align: baseline; }
sup { bottom: 0.5em; } sub { top: 0.25em; }
<strong>、<em> 被屏幕閱讀器識別為語氣增強。<del>/<ins> 配合 datetime 屬性標記修訂時間。<abbr> 必填 title 完整展開形式。