萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

HTML 標籤分類大全:語義化標籤速查與最佳實務

HTML5 提供超過 100 個標籤,依功能分類記憶更高效。本文將標籤分為七大類,附上代表標籤、語義說明與使用建議,並標註棄用標籤避坑指南。

1. 文件結構與元資料

  • <html>, <head>, <title>, <body> — 基礎骨架
  • <meta> — 編碼、視口、SEO、社群分享標籤
  • <link> — CSS、Favicon、預載、預連接
  • <style>, <script>, <noscript> — 內部樣式/腳本/無腳本回退
  • <base> — 相對路徑基準 (謹慎使用)

2. 語義化區塊結構 — 頁面大綱骨幹

標籤語義使用建議
<header>頁首/區塊介紹區包含標題、Logo、導覽、搜尋
<nav>主要導覽連結群僅用於主要導覽,不含所有連結
<main>文檔主要內容每頁**僅一個**,不得為後代
<article>獨立可發布內容文章、部落格、商品、評論
<section>主題性區段通常包含 <h2-h6>,非純樣式容器
<aside>側邊/輔助內容側邊欄、相關連結、廣告、定義
<footer>頁尾/區塊尾部版權、作者、相關連結、聯絡資訊
<div>無語義通用容器找不到更適合語義標籤時使用

3. 文字層級語義 — 內容細節標記

類別標籤語義
標題與分組<h1>-<h6>標題層級 (h1 僅一個)
<p>段落
<hr>主題分隔 (非裝飾線)
<pre>預格式化文本 (代碼/詩歌)
<blockquote>區塊引用 (配合 cite 屬性)
<div>無語義區塊容器
行內語義<a>超連結 (href 必填)
<em>強調語氣
<strong>重要/嚴重/緊急
<small>側註/細則/版權
<mark>高亮/標記 (搜尋關鍵字)
<cite>著作標題引用
<q>行內短引用
<dfn>術語定義處
<abbr>縮寫 (title 給完整名)
<code>行內程式碼
<var>變數名稱
<samp>程式輸出範例
<kbd>鍵盤輸入
編輯追蹤<ins>插入內容 (cite, datetime)
<del>刪除內容 (cite, datetime)
上標下標/注音<sub>, <sup>下標/上標
<ruby>, <rt>, <rp>東亞注音標註
替代呈現<b>關鍵字/產品名 (無語義粗體)
<i>異質文本/外來語/思維 (無語義斜體)
<u>非文字標註 (拼音錯誤、專有名詞)
<bdi>雙向文字隔離自動方向隔離
<bdo>雙向文字覆寫強制方向 dir 屬性
<span>無語義行內容器樣式/腳本掛鉤
<br>語義性換行地址、詩歌
<wbr>建議斷行機會長單字/URL 斷行提示
<time>機器可讀時間datetime 屬性 ISO 8601
<data>機器可讀資料value 屬性對應數值

4. 連結與媒體嵌入

  • <a> — 超連結 (href, target, rel, download)
  • <img> — 圖片 (src, alt 必填, loading, decoding, srcset, sizes)
  • <picture>, <source> — 響應式圖片/格式回退
  • <video>, <audio> — 原生媒體播放 (controls, preload, poster)
  • <track> — 字幕/說明軌
  • <map>, <area> — 圖片熱點地圖
  • <iframe> — 嵌套瀏覽上下文 (sandbox, allow, loading)
  • <embed>, <object>, <param> — 外部應用/外掛 (較少用)

5. 表格資料

  • <table>, <caption>, <thead>, <tbody>, <tfoot>
  • <tr>, <th> (scope), <td>
  • <colgroup>, <col> — 欄群組/欄屬性

6. 表單與互動

  • <form> — 表單容器 (action, method, novalidate)
  • <label> — 標籤 (for 關聯 id)
  • <input> — 輸入欄位 (type: text, email, password, number, date, checkbox, radio, file, hidden, submit, button, color, range 等)
  • <textarea>, <select>, <optgroup>, <option>, <datalist>
  • <button> — 按鈕 (type: submit, reset, button)
  • <fieldset>, <legend> — 欄位群組
  • <output> — 計算結果輸出
  • <progress>, <meter> — 進度條/儀表

7. 互動、腳本與 Web Components

  • <details>, <summary> — 原生摺疊面板
  • <dialog> — 模態/非模態對話框 (showModal())
  • <script> — 腳本 (type="module", defer, async)
  • <noscript> — 無腳本回退
  • <template> — 客戶端模板 (不渲染,JS 克隆使用)
  • <slot> — Web Components 內容分發
  • <canvas> — 位圖繪圖 API

⚠️ 已棄用/避免使用的標籤 (請改用 CSS/語義標籤)

棄用標籤替代方案
<font>CSS font-family, font-size, color
<center>CSS text-align: center 或 Flex/Grid 置中
<strike>, <s><del> (刪除) 或 CSS text-decoration: line-through
<u> (舊語義)CSS text-decoration: underline 或 <mark>/<ins>
<big>CSS font-size: larger 或 rem
<tt><code>, <kbd>, <samp> + CSS font-family: monospace
<frame>, <frameset>, <noframes><iframe> 或 SPA 架構
<acronym><abbr>
<dir><ul>
<isindex><form> + <input>
<applet>Java Applet 已死,勿用
<marquee>, <blink>CSS Animation / JS — 勿用於無障礙

最佳實務總結

  1. 語義優先: 選擇最能表達內容意圖的標籤,而非視覺效果。
  2. 結構清晰: 正確巢狀、標題層級不跳級、區塊語義分明。
  3. 無障礙內建: alt, label, scope, aria-* 同步撰寫。
  4. 驗證習慣: 定期用 W3C Validator 檢查語法錯誤。
  5. 精簡標記: 避免 <div> 炸彈,移除無意義包裹層。

熟悉標籤分類與語義,是寫出高品質 HTML 的核心能力。

copyright © 萬盛學電腦網 all rights reserved