原文地址:https://segmentfault.com/blog/ciaocc/1190000002407912
作者:ciaocc
標簽提供關於 HTML 文檔的元數據。元數據不會顯示在頁面上,但對機器是可讀的,可用於浏覽器(如何顯示內容或重新加載頁面)、搜索引擎(關鍵詞)或其他 web 服務。—— W3School
必要屬性 content 用於定義與 http-equiv 或 name 屬性相關的元信息。可選屬性包括:http-equiv(取值 content-type / expire / refresh / set-cookie,把 content 關聯到 HTTP 頭部)、name(取值 author / description / keywords / generator / revised 等,把 content 關聯到一個名稱)。
頁面關鍵詞:每個網頁應具備一組能準確描述其內容的唯一關鍵詞,使用人們可能搜索、且具描述性和代表性的關鍵字與短語。內容太短可能不被搜索引擎認為相關,且標記不宜超過 874 個字符。
<meta name="keywords" content="your tags" />
頁面描述:每個網頁都應有一個不超過 150 個字符、能準確反映網頁內容的描述標簽。
<meta name="description" content="150 words" />
搜索引擎索引方式:robotterms 是一組以逗號分割的值,通常有 none、noindex、nofollow、all、index 和 follow。務必正確使用 nofollow 和 noindex。
<meta name="robots" content="index,follow" />
<!--
all:文件將被檢索,且頁面上的鏈接可以被查詢;
none:文件將不被檢索,且頁面上的鏈接不可以被查詢;
index:文件將被檢索;
follow:頁面上的鏈接可以被查詢;
noindex:文件將不被檢索;
nofollow:頁面上的鏈接不可以被查詢。
-->
頁面重定向和刷新:content 內的數字代表時間(秒),即多少秒後刷新;若加上 url,則會重定向到指定網頁(搜索引擎能自動檢測,但也容易被誤判為誤導而受罰)。
<meta http-equiv="refresh" content="0;url=" />
其他:
<meta name="author" content="author name" /> <!-- 定義網頁作者 -->
<meta name="google" content="index,follow" />
<meta name="googlebot" content="index,follow" />
viewport:能優化移動浏覽器的顯示。如果不是響應式網站,不要使用 initial-scale 或禁用縮放。大部分 4.7-5 寸設備的 viewport 寬設為 360px;5.5 寸設為 400px;iPhone 6 設為 375px;iPhone 6 Plus 設為 414px。
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
1. width:寬度(數值 / device-width,范圍 200 至 10000,默認 980 像素)
2. height:高度(數值 / device-height,范圍 223 至 10000)
3. initial-scale:初始縮放比例(范圍 >0 到 10)
4. minimum-scale:允許用戶縮放到的最小比例
5. maximum-scale:允許用戶縮放到的最大比例
6. user-scalable:用戶是否可以手動縮放(no, yes)
7. minimal-ui:可在頁面加載時最小化上下狀態欄(已棄用)
注意:很多人給非響應式網站使用 initial-scale=1,這會讓網站以 100% 寬度渲染,用戶需手動移動或縮放;若同時使用 user-scalable=no 或 maximum-scale=1,用戶將無法放大縮小網頁。
WebApp 全屏模式(偽裝 app、離線應用):
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 啟用 WebApp 全屏模式 -->
隱藏狀態欄/設置狀態欄顏色:只有在開啟 WebApp 全屏模式時才生效,content 值為 default | black | black-translucent。
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
添加到主屏後的標題:
<meta name="apple-mobile-web-app-title" content="標題">
忽略數字自動識別為電話號碼:
<meta content="telephone=no" name="format-detection" />
忽略識別郵箱:
<meta content="email=no" name="format-detection" />
添加智能 App 廣告條 Smart App Banner:告訴浏覽器這個網站對應的 app,並在頁面上顯示下載 banner。
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
其他針對各類浏覽器的設置:
聲明編碼:
<meta charset='utf-8' />
優先使用 IE 最新版本和 Chrome:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="X-UA-Compatible" content="IE=6" ><!-- 使用IE6 -->
<meta http-equiv="X-UA-Compatible" content="IE=7" ><!-- 使用IE7 -->
<meta http-equiv="X-UA-Compatible" content="IE=8" ><!-- 使用IE8 -->
浏覽器內核控制:國內浏覽器很多是雙內核(webkit 和 Trident),webkit 內核高速浏覽,IE 內核兼容舊版網站。添加相應 meta 標簽可控制浏覽器選擇用何種內核渲染。
<meta name="renderer" content="webkit|ie-comp|ie-stand">
禁止浏覽器從本地緩存訪問頁面內容(訪客將無法脫機浏覽):
<meta http-equiv="Pragma" content="no-cache">
Windows 8 磁貼:
<meta name="msapplication-TileColor" content="#000"/> <!-- 磁貼顏色 -->
<meta name="msapplication-TileImage" content="icon.png"/> <!-- 磁貼圖標 -->
站點適配:主要用於 PC 頁與手機頁的對應關系。
<meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url">
<!-- [wml|xhtml|html5] 根據手機頁協議語言選擇其一;url 代表當前 PC 頁對應的手機頁 URL,兩者必須一一對應。 -->
轉碼聲明:用百度打開網頁可能會對其轉碼(如貼廣告),添加以下 meta 可避免:
<meta http-equiv="Cache-Control" content="no-siteapp" />
COMPLETE LIST OF HTML META TAGS、W3C META TAGS、METATAGES in HTML5、MDN META TAGS