這篇整理 參考的地址:http://fex.baidu.com/blog/2014/10/html-head-tags/?qq-pf-to=pcqq.c2chtml
meta用的最多的就是 keywords、description、charset、viewport等這樣幾個。這篇整理 就詳細介紹下meta。ios
W3School對meta的解釋:web
標籤提供關於HTML文檔的元數據。元數據不會顯示在頁面上,可是對於機器是可讀的。它可用於瀏覽器(如何顯示內容或從新加載頁面),搜索引擎(關鍵詞),或其餘 web 服務。chrome
meta通常以name、http-equiv 對應 content方式使用。windows
content爲必選屬性,name 、 http-equiv爲可選屬性。瀏覽器
<!--設置頁面編碼方式--> <meta charset="UTF-8">
屬性 | 值 | 描述 | 是否必要 |
content | some text | 定義與http-equiv或name屬性相關的元信息 | 必要 |
http-equiv | content-type / expire / refresh / set-cookie | 把content屬性關聯到HTTP頭部。 | 可選 |
name | author / description / keywords / generator / revised / others | 把 content 屬性關聯到一個名稱。 | 可選 |
關鍵詞:每一個網頁應具備描述該網頁內容的一組惟一的關鍵字。緩存
使用人們可能會搜索,並準確描述網頁上所提供信息的描述性和表明性關鍵字及短語。標記內容過短,則搜索引擎可能不會認爲這些內容相關。另外標記不該超過 874 個字符。cookie
<meta name="keywords" content="your tags" />
頁面描述:每一個網頁都應有一個不超過 150 個字符且能準確反映網頁內容的描述標籤。app
<meta name="description" content="150 words" />
搜索引擎索引方式:robotterms是一組使用逗號(,)分割的值,一般有以下幾種取值:none,noindex,nofollow,all,index和follow。確保正確使用nofollow和noindex屬性值。iphone
<meta name="robots" content="index,follow" /> <!-- all:文件將被檢索,且頁面上的連接能夠被查詢; none:文件將不被檢索,且頁面上的連接不能夠被查詢; index:文件將被檢索; follow:頁面上的連接能夠被查詢; noindex:文件將不被檢索; nofollow:頁面上的連接不能夠被查詢。 -->
頁面重定向和刷新:content內的數字表明時間(秒),既多少時間後刷新。若是加url,則會重定向到指定網頁(搜索引擎可以自動檢測,也很容易被引擎視做誤導而受到懲罰)。
<meta http-equiv="refresh" content="0;url=" />
地理位置標記
<meta name="location" content="province=湖北;city=武漢">
其餘
<!-- 定義網頁做者 --> <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;iphone6設爲375px;ipone6 plus設爲414px。)
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/> <!-- `width=device-width` 會致使 iPhone 5 添加到主屏後以 WebApp 全屏模式打開頁面時出現黑邊 --> <!-- width:寬度(數值 / device-width)(範圍從200 到10,000,默認爲980 像素) height:高度(數值 / device-height)(範圍從223 到10,000) initial-scale:初始的縮放比例 (範圍從>0 到10) minimum-scale:容許用戶縮放到的最小比例 maximum-scale:容許用戶縮放到的最大比例 user-scalable:用戶是否能夠手動縮 (no,yes) minimal-ui:能夠在頁面加載時最小化上下狀態欄。(已棄用) -->
注意:不少人使用initial-scale=1到非響應式網站上,這會讓網站以100%寬度渲染,用戶須要手動移動頁面或者縮放。若是和initial-scale=1同時使用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 name="apple-mobile-web-app-capable" content="yes" /> <!-- 設置蘋果工具欄顏色 --> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <!-- 避免IE使用兼容模式 --> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- 啓用360瀏覽器的極速模式(webkit) --> <meta name="renderer" content="webkit"> <!-- 針對手持設備優化,主要是針對一些老的不識別viewport的瀏覽器,好比黑莓 --> <meta name="HandheldFriendly" content="true"> <!-- 微軟的老式瀏覽器 --> <meta name="MobileOptimized" content="320"> <!-- uc強制豎屏 --> <meta name="screen-orientation" content="portrait"> <!-- QQ強制豎屏 --> <meta name="x5-orientation" content="portrait"> <!-- UC強制全屏 --> <meta name="full-screen" content="yes"> <!-- QQ強制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- UC應用模式 --> <meta name="browsermode" content="application"> <!-- QQ應用模式 --> <meta name="x5-page-mode" content="app"> <!-- windows phone 點擊無高光 --> <meta name="msapplication-tap-highlight" content="no">
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
頁面相關設置
瀏覽器的選擇
<!--優先使用 IE 最新版本和 Chrome--> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!--360 使用Google Chrome Frame (即360使用極速模式)--> <meta name="renderer" content="webkit"> <!-- 注意,使用這段標籤爲了保險起見,加上 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> 一塊兒使用 --> <!--禁止百度轉碼--> <!--經過百度手機打開網頁時,百度可能會對你的網頁進行轉碼,脫下你的衣服,往你的身上貼狗皮膏藥的廣告,爲此可在 head 內添加--> <meta http-equiv="Cache-Control" content="no-siteapp" />
X-UA-Compatible:選擇優先瀏覽器。
renderer:選擇瀏覽器內核。
瀏覽器和內核是有區別的。
目前主流內核有:Trident、Gecko、WebKit、Presto 關於內核更詳細的解釋
目前國內不少瀏覽器都採用雙內核甚至多內核。
如:
搜狗高速瀏覽器、QQ瀏覽器:IE內核(兼容模式)
360極速瀏覽器、遨遊瀏覽器:Webkit內核(極速模式)
禁止瀏覽器從本地計算機的緩存中訪問頁面內容:這樣設定,訪問者將沒法脫機瀏覽。(禁止在非聯網的狀況下訪問本頁內容)
<meta http-equiv="Pragma" content="no-cache">
windows 8設置
<!-- Windows 8 磁貼顏色 --> <meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼圖標 --> <meta name="msapplication-TileImage" content="icon.png"/>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
關於頁面字符編碼和頁面語言
設置頁面字符編碼
<meta charset="utf-8">
設置頁面語言
<!--簡體中文--> <html lang="zh-cmn-Hans"> <!--繁體中文--> <html lang="zh-cmn-Hant">
咱們一般是否是都 lang="zh-CN" 這樣寫?爲啥不這樣寫 看這裏