HTML5 廢除單純「區塊/行內」分類,改用**內容模型** 定義元素可包含的內容類別,共 7 大類:
| 類別 | 代表元素 | 核心規則 |
|---|---|---|
| Metadata | base, link, meta, noscript, script, style, title | 僅允許在 head 中 |
| Flow (流式) | div, p, h1-h6, ul, table, form, section, article, header, footer | 大多數 body 內容,可巢狀 |
| Sectioning (區段) | article, aside, nav, section | 建立大綱節點,可有 header/footer |
| Heading (標題) | h1-h6, hgroup | 標示區段標題 |
| Phrasing (措辭/行內) | a, em, strong, span, img, input, button, label, code, time, br | 段落內文本級語意 |
| Embedded (嵌入) | img, video, audio, canvas, iframe, picture, svg, math | 外部資源嵌入 |
| Interactive (互動) | a, button, details, embed, iframe, label, select, textarea | 用戶互動,**不可巢狀** |
| 傳統分類 | HTML5 內容模型 | 預設 display | 典型元素 |
|---|---|---|---|
| 區塊元素 | Flow / Sectioning | block | div, p, h1-h6, ul, table, form, section |
| 行內元素 | Phrasing / Embedded | inline | span, a, strong, em, img, input, button |
| 行內區塊 | — | inline-block | input, select, img (替換元素) |
| 可變元素 | 視上下文決定 | — | del, ins, map, object, audio, video |
p, h1, span, label) **僅能包含 Phrasing**,不可放 Flow (如 div, p, ul)。<a><button>...</button></a> ❌ 非法。<ul>/<ol> 直系子元素只能是 <li>。<table> 結構嚴格:caption, colgroup, thead, tbody, tfoot, tr, th, td。<dl> 子元素交替 dt、dd。<select> 子元素為 option/optgroup。CSS display 僅改變**渲染盒模型**,**不改變 HTML 內容模型合法性**。<span style="display:block"><div>...</div></span> 在 HTML 解析階段仍非法,瀏覽器會自動修正 DOM 結構 (將 div 提升至 span 外層)。
<article><section><nav><aside><header>/<footer><div><em>、重要 <strong>、標記 <mark>、時間 <time>、代碼 <code>、引用 <q>/<blockquote>。