系統理解標籤類型、屬性機制與字符引用,編寫合規、可維護的 HTML 代碼。
<tag> 或 <tag />br、hr、img、input、meta、link、area、base、col、embed、param、source、track、wbr<tag>內容</tag>div、p、span、a、ul/li、table 等屬性名="屬性值" (雙引號強制,單引號合法但不推薦)disabled、checked、selected、required、hidden、readonly — 存在即 true,可簡寫或寫 disabled="disabled"id、class、style、title、data-*、hidden、tabindex、contenteditable、aria-*、roleonclick 等 (現代推薦 addEventListener)&#字符碼; 例:< → <&#x十六進制碼; 例:< → <&實體名; 例:<、>、&、 、©<!-- 單行註釋 -->
<!--
多行註釋
開始 <!--
結束 -->
不限行數、長度
-->
-- (除開始結束標記外)Node.COMMENT_NODE)| 類別 | 核心標籤 | 特徵 |
|---|---|---|
| Metadata | base、link、meta、noscript、script、style、title | 文檔元資料,多在 head |
| Flow (流式) | div、p、h1-h6、ul、ol、table、form、section、article... | 主要內容容器 |
| Sectioning (區塊) | article、aside、nav、section | 建立文檔大綱節點 |
| Heading (標題) | h1-h6、hgroup | 標題層級 |
| Phrasing (措辭) | a、em、strong、span、img、input、code、time、br... | 段落內文字級內容 |
| Embedded (嵌入) | img、video、audio、canvas、iframe、svg、math... | 外部資源嵌入 |
| Interactive (互動) | a、button、details、embed、iframe、label、select、textarea... | 用戶互動元素 |
| Palpable (可感知) | 大多數 flow/phrasing | 要求非空白內容 |
| 錯誤代碼 | 正確代碼 | 規範依據 |
|---|---|---|
<p><div>...</div></p> | <div><p>...</p></div> | Phrasing content 不能包含 Flow content |
<a><a>...</a></a> | 避免巢狀 | Interactive content 不能巢狀 |
<img src=logo.png> | <img src="logo.png"> | 屬性值必須加引號 |
< input> | <input> | < 後不可有空格 |
<ul><div><li>...</li></div></ul> | <ul><li>...</li></ul> | ul 只能直接包含 li |
嚴守分類規範與語法規則,讓瀏覽器解析器專注渲染,而非容錯修復。