萬盛學電腦網

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

HTML 語言標籤核心概念:文件結構、字元編碼、連結與表單基礎

HTML 語言標籤核心概念

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> 包含所有可見內容。

字元編碼與 MIME 類型

  • <meta charset="UTF-8">:HTML5 簡寫,等同 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">。
  • 常見編碼:UTF-8 (推薦), Big5, GB2312, ISO-8859-1 等。瀏覽器若未偵測到編碼會嘗試猜測,導致亂碼。
  • 伺服器回應標頭 Content-Type: text/html; charset=UTF-8 優先級高於 meta 標籤。

背景與色彩屬性(已淘汰,改用 CSS)

屬性用途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">。
  • Email/電話: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 (檔案上傳)。

掌握核心標籤與現代替代方案,是前端開發的基石。

copyright © 萬盛學電腦網 all rights reserved