HTML 學習不只是背標籤,而是理解文檔結構、語義化表達、與 CSS/JS 協作的完整體系。本文提供結構化學習路徑與實戰架構。
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="頁面描述">
<title>頁面標題 | 網站名稱</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="css/main.css">
<style>/* 關鍵內聯 CSS */</style>
</head>
<body>
<header><!-- 頁首:Logo、導航 --></header>
<main><!-- 主要內容區 --></main>
<footer><!-- 頁腳:版權、連結 --></footer>
<script src="js/app.js" defer></script>
</body>
</html>
| 方式 | 語法 | 優點 | 缺點 | 適用場景 |
|---|---|---|---|---|
| 內聯樣式 | style="color:red" |
優先級最高、快速測試 | 混雜結構、難維護、無法復用 | 極少數動態樣式、Email |
| 內部樣式 | <style>...</style> |
單檔案完整、無額外請求 | 無法跨頁復用、增加 HTML 體積 | 單頁應用、原型、關鍵 CSS |
| 外部連結 | <link rel="stylesheet"> |
瀏覽器快取、團隊協作、關注點分離 | 額外 HTTP 請求(HTTP/2 緩解) | 所有正式專案(標準做法) |
css/
├── reset.css # 重置/標準化
├── variables.css # CSS 變數(色彩、間距、字體)
├── base/
│ ├── typography.css # 文字排版
│ └── forms.css # 表單基礎
├── components/ # UI 組件
│ ├── button.css
│ ├── card.css
│ └── modal.css
├── layout/
│ ├── grid.css # 佈局系統
│ ├── header.css
│ └── footer.css
├── pages/ # 頁面專用
│ ├── home.css
│ └── dashboard.css
├── utilities.css # 工具類
└── main.css # 總匯入(建構入口)
<div> 包裹所有東西 → ✅ 語義化標籤<br> 做間距 → ✅ CSS margin/padding扎實的 HTML 基礎,是 CSS 與 JavaScript 發揮最大效能的前提。