< meta > 元素
定義
meta標(biāo)簽提供關(guān)于HTML文檔的元數(shù)據(jù)朝蜘。元數(shù)據(jù)不會(huì)顯示在頁面上蚂四,但是對(duì)于機(jī)器是可讀的歼疮。它可用于瀏覽器(如何顯示內(nèi)容或重新加載頁面)署咽,搜索引擎(關(guān)鍵詞)近顷,或其他 web 服務(wù)生音。使用meta標(biāo)簽時(shí)無需將標(biāo)簽閉合。必要屬性
屬性 | 值 | 描述 |
---|---|---|
content | some text | 定義與http-equiv或name屬性相關(guān)的元信息 |
- 可選屬性
屬性 | 值 | 描述 |
---|---|---|
http-equiv | content-type / expire / refresh / set-cookie | 把content屬性關(guān)聯(lián)到HTTP頭部窒升。 |
name | author / description / keywords / generator / revised / others | 把 content 屬性關(guān)聯(lián)到一個(gè)名稱缀遍。 |
content | some text | 定義用于翻譯 content 屬性值的格式。 |
SEO優(yōu)化
頁面關(guān)鍵詞
每個(gè)網(wǎng)頁應(yīng)具有描述該網(wǎng)頁內(nèi)容的一組唯一的關(guān)鍵字饱须。使用人們可能會(huì)搜索域醇,并準(zhǔn)確描述網(wǎng)頁上所提供信息的描述性和代表性關(guān)鍵字及短語。標(biāo)記內(nèi)容太短蓉媳,則搜索引擎可能不會(huì)認(rèn)為這些內(nèi)容相關(guān)譬挚。另外標(biāo)記不應(yīng)超過 874 個(gè)字符。
<meta name="keywords" content="your tags" />
頁面描述
每個(gè)網(wǎng)頁都應(yīng)有一個(gè)不超過 150 個(gè)字符且能準(zhǔn)確反映網(wǎng)頁內(nèi)容的描述標(biāo)簽酪呻。
<meta name="description" content="150 words" />
搜索引擎索引方式
robotterms是一組使用逗號(hào)(,)分割的值减宣,通常有如下幾種取值:none,noindex玩荠,nofollow漆腌,all,index和follow阶冈。確保正確使用nofollow和noindex屬性值闷尿。
<meta name="robots" content="index,follow" />
頁面重定向和刷新
content內(nèi)的數(shù)字代表時(shí)間(秒),既多少時(shí)間后刷新女坑。如果加url,則會(huì)重定向到指定網(wǎng)頁(搜索引擎能夠自動(dòng)檢測(cè)悠砚,也很容易被引擎視作誤導(dǎo)而受到懲罰)。
<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" />
<meta name="verify" content="index,follow" />
移動(dòng)設(shè)備
viewport
能優(yōu)化移動(dòng)瀏覽器的顯示堂飞。如果不是響應(yīng)式網(wǎng)站灌旧,不要使用initial-scale或者禁用縮放。大部分4.7-5寸設(shè)備的viewport寬設(shè)為360px绰筛;5.5寸設(shè)備設(shè)為400px枢泰;iphone6設(shè)為375px;ipone6 plus設(shè)為414px铝噩。
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
1.width:寬度(數(shù)值 / device-width)(范圍從200 到10,000衡蚂,默認(rèn)為980 像素)
2.height:高度(數(shù)值 / device-height)(范圍從223 到10,000)
3.initial-scale:初始的縮放比例 (范圍從>0 到10)
4.minimum-scale:允許用戶縮放到的最小比例
5.maximum-scale:允許用戶縮放到的最大比例
6.user-scalable:用戶是否可以手動(dòng)縮 (no,yes)
7.minimal-ui:可以在頁面加載時(shí)最小化上下狀態(tài)欄。(已棄用)
注意骏庸,很多人使用initial-scale=1到非響應(yīng)式網(wǎng)站上毛甲,這會(huì)讓網(wǎng)站以100%寬度渲染,用戶需要手動(dòng)移動(dòng)頁面或者縮放具被。如果和initial-scale=1同時(shí)使用user-scalable=no或maximum-scale=1玻募,則用戶將不能放大/縮小網(wǎng)頁來看到全部的內(nèi)容。
WebApp全屏模式
偽裝app一姿,離線應(yīng)用七咧。
<meta name="apple-mobile-web-app-capable" content="yes" />
隱藏狀態(tài)欄/設(shè)置狀態(tài)欄顏色
只有在開啟WebApp全屏模式時(shí)才生效跃惫。content的值為default | black | black-translucent 。
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
添加到主屏后的標(biāo)題
<meta name="apple-mobile-web-app-title" content="標(biāo)題">
忽略數(shù)字自動(dòng)識(shí)別為電話號(hào)碼
<meta content="telephone=no" name="format-detection" />
忽略識(shí)別郵箱
<meta content="email=no" name="format-detection" />
添加智能 App 廣告條 Smart App Banner
告訴瀏覽器這個(gè)網(wǎng)站對(duì)應(yīng)的app艾栋,并在頁面上顯示下載banner(如下圖)爆存。
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
其他
<meta name="HandheldFriendly" content="true">
<meta name="MobileOptimized" content="320">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<meta name="browsermode" content="application">
<meta name="x5-page-mode" content="app">
<meta name="msapplication-tap-highlight" content="no">
網(wǎng)頁相關(guān)
申明編碼
<meta charset='utf-8' />
優(yōu)先使用 IE 最新版本和 Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="X-UA-Compatible" content="IE=6" >
<meta http-equiv="X-UA-Compatible" content="IE=7" >
<meta http-equiv="X-UA-Compatible" content="IE=8" >
瀏覽器內(nèi)核控制
國(guó)內(nèi)瀏覽器很多都是雙內(nèi)核(webkit和Trident),webkit內(nèi)核高速瀏覽蝗砾,IE內(nèi)核兼容網(wǎng)頁和舊版網(wǎng)站先较。而添加meta標(biāo)簽的網(wǎng)站可以控制瀏覽器選擇何種內(nèi)核渲染。
<meta name="renderer" content="webkit|ie-comp|ie-stand">
國(guó)內(nèi)雙核瀏覽器默認(rèn)內(nèi)核模式如下
1.搜狗高速瀏覽器悼粮、QQ瀏覽器:IE內(nèi)核(兼容模式)
2.360極速瀏覽器闲勺、遨游瀏覽器:Webkit內(nèi)核(極速模式)
禁止瀏覽器從本地計(jì)算機(jī)的緩存中訪問頁面內(nèi)容
這樣設(shè)定,訪問者將無法脫機(jī)瀏覽矮锈。
Windows 8
<meta name="msapplication-TileColor" content="#000"/>
<meta name="msapplication-TileImage" content="icon.png"/>
站點(diǎn)適配
主要用于PC-手機(jī)頁的對(duì)應(yīng)關(guān)系。
<meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url">
轉(zhuǎn)碼申明
用百度打開網(wǎng)頁可能會(huì)對(duì)其進(jìn)行轉(zhuǎn)碼(比如貼廣告),避免轉(zhuǎn)碼可添加如下meta
<meta http-equiv="Cache-Control" content="no-siteapp" />
地理標(biāo)簽
<meta name="ICBM" content="latitude, longitude">
<meta name="geo.position" content="latitude;longitude">
<meta name="geo.region" content="country[-state]">
<meta name="geo.placename" content="city/town">