HTML (HyperText Markup Language) 是網頁的骨架。本文梳理文件結構、字元編碼、連結、表單、背景與邊界等核心標籤與屬性,建立扎實基礎。
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<title>頁面標題</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="頁面描述">
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- 可見內容 -->
</body>
</html>
<html> 根元素,lang 指定語言,利於 SEO 與螢幕閱讀器。<head> 包含元資料,不直接渲染。<body> 包含所有可見內容。<meta charset="UTF-8">:HTML5 簡寫,等同 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">。Content-Type: text/html; charset=UTF-8 優先級高於 meta 標籤。| 屬性 | 用途 | CSS 替代 |
|---|---|---|
bgcolor | 背景顏色 | background-color |
background | 背景圖片 | background-image |
bgproperties="fixed" | 固定背景不捲動 | background-attachment: fixed |
text | 一般文字顏色 | color |
link | 未訪問連結顏色 | :link { color } |
vlink | 已訪問連結顏色 | :visited { color } |
alink | 點擊中連結顏色 | :active { color } |
leftmargin, topmargin | 頁面邊界 | margin on body |
色碼格式:#RRGGBB 十六進位 RGB,各兩位數 00-FF。
<a> 完整用法<a href="https://example.com">連結文字</a><a href="#section1">跳轉</a> 對應 <section id="section1">。<a href="page.html#section">。<a href="..." target="_blank" rel="noopener noreferrer">(安全性必加 rel)。<a href="file.pdf" download="新檔名.pdf">。mailto:email@example.com, tel:+886-2-1234567。<hr>size, width, align, noshade, color → 全部改用 CSS。<form action="/submit" method="POST">
<label for="name">姓名</label>
<input type="text" id="name" name="name" required>
<button type="submit">送出</button>
</form>
method:GET (查詢字串) 或 POST (請求主體)。enctype:application/x-www-form-urlencoded (預設), multipart/form-data (檔案上傳)。掌握核心標籤與現代替代方案,是前端開發的基石。