萬盛學電腦網

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

HTML `` 標籤完全手冊:HTTP-EQUIV、NAME、SEO、緩存、跳轉、編碼

<meta> 是文檔元數據的核心載體,雖不直接渲染可見內容,卻控制著瀏覽器解析、搜尋引擎索引、緩存策略、響應式適配等關鍵行為。本文按 **HTTP-EQUIV(HTTP 模擬頭)**、**NAME(頁面描述)**、**其他關鍵標籤** 三大類別系統整理。

一、HTTP-EQUIV:模擬 HTTP 響應頭

http-equiv 值作用標準寫法示例
Content-Type聲明文檔類型與字符集<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
X-UA-Compatible指定 IE 渲染引擎模式<meta http-equiv="X-UA-Compatible" content="IE=edge">
refresh定時刷新或跳轉<meta http-equiv="refresh" content="5;url=https://example.com">
expires設置緩存過期時間<meta http-equiv="expires" content="0"> (立即過期)
cache-control控制緩存機制<meta http-equiv="cache-control" content="no-cache, must-revalidate">
pragma兼容 HTTP/1.0 緩存控制<meta http-equiv="pragma" content="no-cache">
set-cookie設置 Cookie(非標準,慎用)<meta http-equiv="set-cookie" content="name=value; expires=...">
window-target強制在頂層窗口打開(防框架嵌套)<meta http-equiv="window-target" content="_top">
page-enter / page-exit頁面進入/退出濾鏡特效(IE 專屬)<meta http-equiv="page-enter" content="blendTrans(Duration=0.5)">
> ⚠️ **注意**:`http-equiv` 優先級低於真實 HTTP 響應頭。生產環境**首選在 Nginx/Apache/CDN 配置真實響應頭**,`` 做兜底。

二、NAME:頁面描述與 SEO 核心

name 值用途示例
viewport響應式視口控制(核心)<meta name="viewport" content="width=device-width, initial-scale=1.0">
description頁面描述(搜尋結果摘要)<meta name="description" content="專業前端技術教程,涵蓋 HTML/CSS/JS/框架實戰">
keywords關鍵詞(現代搜尋引擎權重極低)<meta name="keywords" content="HTML, CSS, JavaScript, 前端">
robots爬蟲指令<meta name="robots" content="index, follow"> / noindex, nofollow
author作者信息<meta name="author" content="張三 <zhang@example.com>">
generator生成工具標識<meta name="generator" content="VitePress 1.0">
copyright版權聲明<meta name="copyright" content="© 2024 Example Inc.">
revisit-after建議重抓取間隔(參考值)<meta name="revisit-after" content="7 days">
renderer雙核瀏覽器指定內核(國產瀏覽器)<meta name="renderer" content="webkit">
format-detection禁用電話/郵箱自動識別<meta name="format-detection" content="telephone=no, email=no">

三、其他關鍵標籤

標籤作用示例
<link rel="icon">網站圖標<link rel="icon" href="/favicon.ico"> / <link rel="apple-touch-icon" href="/icon-192.png">
<link rel="canonical">規範化 URL,防重複收錄<link rel="canonical" href="https://example.com/original-page">
<link rel="preload">資源預加載<link rel="preload" as="font" href="/font.woff2" crossorigin>
<base>頁面所有相對鏈接基準 URL<base href="https://cdn.example.com/" target="_blank">
<meta charset>HTML5 簡寫聲明編碼<meta charset="UTF-8"> (必須在 head 前 1024 字節內)

四、現代項目 `` 標準模板

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="頁面描述,150字內,包含核心關鍵詞">
  <meta name="keywords" content="關鍵詞1,關鍵詞2,關鍵詞3">
  <meta name="robots" content="index, follow">
  <meta name="author" content="作者名">
  <link rel="canonical" href="當前頁面絕對URL">
  <link rel="icon" href="/favicon.ico">
  <link rel="apple-touch-icon" href="/icon-192.png">
  <title>頁面標題 | 站點名稱</title>
  <!-- CSS/JS 預加載、內聯關鍵 CSS -->
</head>

五、常見誤區避雷

  1. 以為 `` 能完全控制緩存 → **無效於代理/CDN,必須配服務端頭**
  2. 2. `keywords` 還有高權重 → **Google 2009 年官方宣布忽略,百度權重極低** 3. `refresh` 做頁面跳轉 → **破壞後退按鈕、SEO 不友好、可訪問性差**,請用 301/302 重定向或 JS `location.href` 4. `charset` 寫在 `` 之後 → **必須在 head 前 1024 字節內,建議緊跟 `<head>` 後**</li> 5. 重複定義 `viewport` → **最後一個生效,易導致適配混亂**</li> </ol> <h2>結語</h2> <p><code><meta></code> 雖小,卻是頁面與瀏覽器、搜尋引擎、緩存系統溝通的橋樑。掌握核心屬性、避開常見坑點、建立項目標準 `<head>` 模板,是專業前端的基本功。</p> <div class="ad2"> <script language='javascript' src='/ad/tad.js'></script> </div> </div> <div> <div class="pageNum"> <ul> <li>上一篇程序編程: <a class='LinkPrevArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35180.html' >IE6 圖片底部神秘空白間隙:五大根因與對應解決方案</a> <li>下一篇程序編程: <a class='LinkNextArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35182.html' >Web 安全色與 16 進制顏色代碼速查表:紅/藍/綠/黃/紫/中性色系</a> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=hebxbne_left-div-2> <h2 style="text-align:left">HTML 腳本教學排行</h2> <ul> <li><a class="font7 nleft" title="純 HTML 頁面實現表單提交、參數傳遞與身份驗證的實戰方案" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35113.html">純 HTML 頁面實現表單提交、參數傳遞與身份驗證的實戰方案</a></li> <li><a class="font7 nleft" title="構建現代 HTML5 Web 頁面:語義化結構、Doctype、兼容策略、樣式最…" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35191.html">構建現代 HTML5 Web 頁面:語義化結構、Doctype、兼容策略、樣式最…</a></li> <li><a class="font7 nleft" title="HTML 網頁 Head 區塊完整指南:Base、Meta、CSS/JS 融合、…" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35071.html">HTML 網頁 Head 區塊完整指南:Base、Meta、CSS/JS 融合、…</a></li> <li><a class="font7 nleft" title="深度解析 JavaScript this 綁定:四大調用模式與陷阱避坑" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34792.html">深度解析 JavaScript this 綁定:四大調用模式與陷阱避坑</a></li> <li><a class="font7 nleft" title="HTML 超連結標籤 <a> 完整屬性、事件與 DOM 介面參考手冊" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34971.html">HTML 超連結標籤 <a> 完整屬性、事件與 DOM 介面參考手冊</a></li> </ul> </div> <div class=kenbxne_js></div> </div> <div class="nright hebxbne_right"> <div class=guanggao1 id=guanggao_r1></div> <div class=kenbxne_js></div> <div class=hebxbne_right-div1> <h2>推薦文章</h2> <div class=kenbxne_js></div> <ul class=hebxbne_right-list1> <li><a class="font7 nleft" title="HTML <dl> 定義列表:語義化「名詞-解釋」結構" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34869.html">HTML <dl> 定義列表:語義化「名詞-解釋」結構</a></li> <li><a class="font7 nleft" title="Windows 98 將 HTML 文件設為動態桌面背景完整教學" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34984.html">Windows 98 將 HTML 文件設為動態桌面背景完整教學</a></li> <li><a class="font7 nleft" title="XHTML+CSS 跨瀏覽器相容性五大經典解決方案" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34907.html">XHTML+CSS 跨瀏覽器相容性五大經典解決方案</a></li> <li><a class="font7 nleft" title="實用卻被忽略的 HTML 標籤:base、caption、thead/tbody…" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35208.html">實用卻被忽略的 HTML 標籤:base、caption、thead/tbody…</a></li> <li><a class="font7 nleft" title="IE 條件註釋 Hack 完整速查表:精準定位各版本 IE" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34789.html">IE 條件註釋 Hack 完整速查表:精準定位各版本 IE</a></li> <li><a class="font7 nleft" title="正則表達式過濾 HTML 危險腳本:XSS 防護核心規則與代碼實現" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35145.html">正則表達式過濾 HTML 危險腳本:XSS 防護核心規則與代碼實現</a></li> <li><a class="font7 nleft" title="網頁直接列印優化指南:@media print、背景列印問題與 img 標籤策略" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35211.html">網頁直接列印優化指南:@media print、背景列印問題與 img 標籤策略</a></li> <li><a class="font7 nleft" title="HTML 表格水平對齊屬性 ALIGN 詳解" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35047.html">HTML 表格水平對齊屬性 ALIGN 詳解</a></li> <li><a class="font7 nleft" title="網頁木馬 HTML.TrojDown 分析:利用 MHT 漏洞投放 rundll…" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/34902.html">網頁木馬 HTML.TrojDown 分析:利用 MHT 漏洞投放 rundll…</a></li> <li><a class="font7 nleft" title="HTML `<meta>` 標籤完全手冊:HTTP-EQUIV、NAME、SEO…" href="https://twcomputer.wsxdn.com/programming/webproduction/htmlscripttutorial/201510/35181.html">HTML `<meta>` 標籤完全手冊:HTTP-EQUIV、NAME、SEO…</a></li> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=plnebxmj> <div class="plnebxmj-2 flink"> <h2><a class=bottom href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a>| <a class=bottom hreflang="ja" href="https://jp.wsxdn.com/" target=_blank>日本語版</a> | <a class=bottom onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('https://twcomputer.wsxdn.com');" href="#">設為首頁</a> | <a class=bottom href="javascript:window.external.addfavorite('https://twcomputer.wsxdn.com','萬盛學電腦網');">加入收藏</a></h2> </div> <div class=knemnnx></div> </div> <div class="ojwbxnks">copyright © <a title="萬盛學電腦網" href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a> all rights reserved <br> </div> </div> </body> </html>