HTML 文檔結構分為兩大部分:<head>(文檔元資料,瀏覽器不直接顯示)與 <body>(可見內容)。雖然 FrontPage、Dreamweaver 等視覺化工具讓不懂代碼也能做專業網頁,但它們無法自動生成優質的 Head 區塊,因此深入理解 Head 內部元素至關重要。
<meta> 標籤記錄頁面關鍵信息,主要有兩大用途:
text/html; charset=utf-8)核心屬性:
http-equiv:模擬 HTTP 響應頭(如 Content-Type、refresh)name:頁面描述信息(如 keywords、description、author)content:具體數值,配合上述屬性使用<title> 定義網頁標題,顯示在瀏覽器標籤、收藏夾、搜索結果中,是 SEO 權重最高的標籤之一。
配合 http-equiv="refresh" 可實現定時刷新或延遲跳轉:
<meta http-equiv="refresh" content="5;url=index.html">
表示 5 秒後跳轉至 index.html;content="0;url=..." 即時跳轉。
<base href="https://example.com/" target="_blank"> 設定頁面所有相對鏈接的基準 URL 與默認打開方式,常用於框架頁指定目標框架(如 target="main")。
定義文檔與外部資源(CSS、RSS、圖標)的關係:
rel="stylesheet":引入樣式表rel="icon":網站圖標rel="alternate":RSS/Atom 訂閱源<title>HEAD元素使用集錦</title>
<!-- 網頁標題 -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!-- 網頁內容類型與編碼 -->
<meta name="keywords" content="HEAD元素">
<!-- 關鍵字信息 -->
<meta name="description" content="本網頁用於說明HEAD元素的使用方式">
<!-- 頁面描述 -->
<meta http-equiv="refresh" content="5;URL=index.htm">
<!-- 5秒後自動跳轉 -->
<base href="" target="_blank">
<!-- 基礎鏈接設定,新窗口打開 -->
<link rel="stylesheet" href="homepage.css">
<!-- 引入樣式表 -->
掌握這些元素,能讓你的網頁在瀏覽器渲染、搜索引擎收錄、用戶體驗三方面都更專業。