萬盛學電腦網

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

HTML 教學完整路線圖:從入門到語意化、無障礙、效能、現代工具鏈的進階之路

HTML 是 Web 開發的基石,但「會寫幾個標籤」與「寫出專業級 HTML」有巨大鴻溝。本文提供結構化、階段性、實戰導向的完整學習路線圖,助你從零建立扎實前端根基。

階段 0:環境與工具 (Day 1)

  • **編輯器:** VS Code (必裝擴充:Live Server, Prettier, HTMLHint/Markuplint, Emmet, Auto Rename Tag, IntelliSense for CSS class names)
  • **瀏覽器:** Chrome/Edge DevTools 精通 (Elements, Console, Network, Performance, Lighthouse, Accessibility, Rendering)
  • **版控:** Git + GitHub (建立 repo、commit、push、PR、GitHub Pages 部署)
  • **終端機:** 基本指令 (`ls`, `cd`, `mkdir`, `npm`, `npx`)

階段 1:核心語法與文件結構 (Week 1-2)

  • **標準骨架:** ``, ``, `` (meta charset/viewport/title/description/OG), ``
  • **高頻標籤分類掌握 (20% 標籤解決 80% 場景):**
    • 文字語意:`h1-h6`, `p`, `strong`, `em`, `blockquote`, `cite`, `code`, `pre`, `mark`, `time`, `abbr`, `ruby/rt/rp`
    • 列表:`ul`, `ol`, `li`, `dl`, `dt`, `dd`
    • 連結/媒體:`a` (href/target/rel/download), `img` (src/alt/width/height/loading/srcset/sizes), `picture/source`, `video`, `audio`, `iframe`
    • 表單:`form`, `input` (type/name/value/placeholder/required/disabled/readonly/autocomplete/list), `textarea`, `select/option/optgroup`, `button`, `label` (for), `fieldset/legend`, `datalist`, `output`, `progress`, `meter`
    • 表格:`table`, `caption`, `thead/tbody/tfoot`, `tr`, `th` (scope), `td`, `colgroup/col`
    • 語意區塊:`header`, `nav`, `main`, `article`, `section`, `aside`, `footer`, `figure`, `figcaption`, `details/summary`, `dialog`
    • 通用容器:`div`, `span` (最後手段)
  • **屬性精通:** 全域屬性 (`id`, `class`, `style`, `data-*`, `aria-*`, `hidden`, `tabindex`, `contenteditable`, `title`)、專有屬性、布林屬性 (`disabled`, `readonly`, `required`, `hidden`, `multiple`, `autofocus`)、事件屬性 (認知即可,實務用 `addEventListener`)。
  • **實體編碼:** `<`, `>`, `&`, `"`, `'`, ` `, ` `, ` `, `­`。
  • **驗證習慣:** 每存檔即 `W3C Validator` / `HTMLHint` / `Markuplint` 檢查,紅錯誤零容忍。

階段 2:語意化、無障礙、SEO 三位一體 (Week 3-4)

  • **語意化決策樹:** 遇到 `
    `/`` 必問:「有語意標籤能取代嗎?」
  • **文件大綱:** 單一 `

    `、層級不跳級 (h1→h2→h3)、`section`/`article` 重置大綱 (HTML5 Outline Algorithm 雖未完全實作,但語意結構仍關鍵)。

  • **ARIA 基礎:** `role` (button, dialog, navigation, search, alert, region)、`aria-label/labelledby/describedby`, `aria-hidden`, `aria-expanded`, `aria-controls`, `aria-live` (polite/assertive)、`aria-current` (導覽當前頁)。**原生標籤優先,ARIA 補足。**
  • **鍵盤導航:** `Tab` 順序邏輯、焦點可見 (`:focus-visible`)、`Skip to main content` 連結、Modal 焦點陷阱、ESC 關閉。
  • **螢幕閱讀器實測:** NVDA (Win) / VoiceOver (Mac/iOS) / TalkBack (Android) / Orca (Linux)。
  • **SEO 技術優化:** Title/Description/OG/Twitter Card/Canonical/JSON-LD Schema.org (Article, Product, Breadcrumb, FAQ, Organization, WebSite)、語意化結構、載入速度、行動友善、HTTPS、Sitemap/Robots.txt。

階段 3:現代 HTML5 API 與進階特性 (Week 5-6)

  • **表單原生驗證:** `:valid`/`:invalid`/`:user-invalid` (CSS)、`setCustomValidity()`、`reportValidity()`、`checkValidity()`、`novalidate`、Constraint Validation API。
  • **原生對話框:** `` + `showModal()`/`show()`/`close()` + `::backdrop` 樣式 + `autofocus` + ESC 關閉 + 焦點管理。
  • **Web Components:** `customElements.define()`, Shadow DOM (`attachShadow({mode:'open'})`), `