查找總結了一些HTML5頭部<head>標簽常用信息,有錯誤的,敬請留言指正,或可以留言補充,歡迎留言交流!
<!-- 字體編碼 --> <meta charset="utf-8" /> <!-- 關鍵字 --> <meta name="keywords" content="" /> <!-- 說明 --> <meta name="description" content="" /> <!-- 作者 --> <meta name="author" content="" /> <!-- 設置文檔寬度、是否縮放 --> <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" /> <!-- 優先使用IE最新版本或chrome --> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 360讀取到這個標簽立即錢換到極速模式 --> <meta name="renderer" content="webkit" /> <!-- 禁止百度轉碼 --> <meta http-equiv="Cache-Control" content="no-siteapp" /> <!-- UC強制豎屏 --> <meta name="screen-orientation" content="portrait" /> <!-- QQ強制豎屏 --> <meta name="x5-orientation" content="portrait" /> <!-- UC強制全屏 --> <meta name="full-scerrn" content="yes" /> <!-- QQ強制全屏 --> <meta name="x5-fullscreen" content="ture" /> <!-- QQ應用模式 --> <meta name="x5-page-mode" content="app" /> <!-- UC應用模式 --> <meta name="browsermode" content="application"> <!-- window phone 點亮無高光 --> <meta name="msapplication-tap-highlight" content="no" /> <!-- 安卓設備不自動識別郵件地址 --> <meta name="format-detection" name="email=no" /> <!-- iOS設備 --> <!-- 添加到主屏幕的標題 --> <meta name="apple-mobile-web-app-title" content="標題" /> <!-- 是否啟用webApp全屏 --> <meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 設置狀態欄的背景顏色,啟用webapp模式時生效 --> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent/black/default" /> <!-- 半透明/黑色/默認白色 --> <!-- 禁止數字識別為電話號碼 --> <meta name="format-detection" content="telephone=no" /> <!-- 智能添加廣告條 --> <meta name="apple-itunes-app" content="app-id=myappstoreID,affiliate-data=myaffiliatedata,app-argument=myurl" />
為移動設備添加 viewport
viewport 可以讓布局在移動瀏覽器上顯示的更好。 通常會寫
<meta name ="viewport" content ="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
<!-- `width=device-width` 會導致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時出現黑邊
http://bigc.at/ios-webapp-viewport-meta.orz -->
content 參數:
- width viewport 寬度(數值/device-width)
- height viewport 高度(數值/device-height)
- initial-scale 初始縮放比例
- maximum-scale 最大縮放比例
- minimum-scale 最小縮放比例
- user-scalable 是否允許用戶縮放(yes/no)
- minimal-ui iOS 7.1 beta 2 中新增屬性(注意:iOS8 中已經刪除),可以在頁面加載時最小化上下狀態欄。這是一個布爾值,可以直接這樣寫:
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
而如果你的網站不是響應式的,請不要使用 initial-scale 或者禁用縮放。
<meta name="viewport" content="width=device-width,user-scalable=yes">
適配 iPhone 6 和 iPhone 6plus 則需要寫:
<meta name="viewport" content="width=375"> <meta name="viewport" content="width=414">
大部分 4.7~5 寸的安卓設備的 viewport 寬設為 360px,iPhone 6 上卻是 375px,大部分 5.5 寸安卓機器(比如說三星 Note)的 viewport 寬為 400,iPhone 6 plus 上是 414px。
SEO 優化部分
頁面標題<title>標簽(head 頭部必須)
<title>your title</title>
頁面關鍵詞 keywords
<meta name="keywords" content="your keywords">
頁面描述內容 description
<meta name="description" content="your description">
定義網頁作者 author
<meta name="author" content="author,email address">
定義網頁搜索引擎索引方式,robotterms 是一組使用英文逗號「,」分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。
<meta name="robots" content="index,follow">
百度禁止轉碼
通過百度手機打開網頁時,百度可能會對你的網頁進行轉碼,脫下你的衣服,往你的身上貼狗皮膏葯的廣告,為此可在 head 內添加
<meta http-equiv="Cache-Control" content="no-siteapp" />
不推薦的 meta 屬性
下面是不推薦使用的 meta 屬性,因為它們采用率低,或已棄用:
<!-- 用於聲明文檔語言,但支持得不是很好。最好使用 <html lang=""> --> <meta name="language" content="en"> <!-- Google 無視 & Bing 認為垃圾的指示器 --> <meta name="keywords" content="你,關鍵字,在這里,不使用空格,而用逗號進行分隔"> <!-- 目前沒有在任何搜索引擎中使用過的聲明 --> <meta name="revised" content="Sunday, July 18th, 2010, 5:15 pm"> <!-- 為垃圾郵件機器人收獲 email 地址提供了一種簡單的方式 --> <meta name="reply-to" content="email@example.com"> <!-- 最好使用 <link rel="author"> 或 humans.txt 文件 --> <meta name="author" content="name, email@example.com"> <meta name="designer" content=""> <meta name="owner" content=""> <!-- 告訴搜索機器人一段時間后重新訪問該網頁。這不支持,因為大多數搜索引擎使用隨機時間間隔來重新抓取網頁 --> <meta name="revisit-after" content="7 days"> <!-- 在一段時間后將用戶重定向到新的 URL --> <!-- W3C 建議不要使用該標簽。Google 建議使用服務器端的 301 重定向。--> <meta http-equiv="refresh" content="300; url=https://example.com/"> <!-- 描述網站的主題 --> <meta name="topic" content=""> <!-- 公司概要或網站目的 --> <meta name="summary" content=""> <!-- 一個已廢棄的標簽,和關鍵詞 meta 標簽的作用相同 --> <meta name="classification" content="business"> <!-- 是否是相同的 URL,年代久遠且不支持 --> <meta name="identifier-URL" content="https://example.com/"> <!-- 和關鍵詞標簽類似的功能 --> <meta name="category" content=""> <!-- 確保你的網站在所有國家和語言中都能顯示 --> <meta name="coverage" content="Worldwide"> <!-- 和 coverage 標簽相同 --> <meta name="distribution" content="Global"> <!-- 控制在互聯網上哪些用戶可以訪問 --> <meta http-equiv="Pics-label" content="value"> <!-- 緩存控制 --> <!-- 最好在服務器端配置緩存控制 --> <meta http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache">
link 標簽
說到 link 標簽,估計大家的第一反應和我一樣,就是引入外部CSS樣式文件的,不錯,這是 link 標簽最最常用的功能。不過它還有很多別的用處,比如這是瀏覽器 favicon 圖標,touch圖標等等。
<!-- 有助於防止出現內容重復的問題 --> <link rel="canonical" href="https://example.com/2010/06/9-things-to-do-before-entering-social-media.html"> <!-- 之前用於包含 icon 鏈接,但已被廢棄並不再使用 --> <link rel="shortlink" href="https://example.com/?p=42"> <!-- 鏈接到當前文檔的一個 AMP HTML 版本 --> <link rel="amphtml" href="https://example.com/path/to/amp-version.html"> <!-- 表明一個 CSS 樣式表 --> <link rel="stylesheet" href="https://example.com/styles.css"> <!-- 鏈接到一個指定 Web 應用程序“安裝”證書的 JSON 文件 --> <link rel="manifest" href="manifest.json"> <!-- 鏈接到文檔的作者 --> <link rel="author" href="humans.txt"> <!-- 指向一個適用於鏈接內容的版權申明 --> <link rel="copyright" href="copyright.html"> <!-- 給出可能的你的另一種語言的文檔位置參考 --> <link rel="alternate" href="https://es.example.com/" hreflang="es"> <!-- 提供了關於作者或其他人的信息 --> <link rel="me" href="https://google.com/profiles/thenextweb" type="text/html"> <link rel="me" href="mailto:name@example.com"> <link rel="me" href="sms:+15035550125"> <!-- 鏈接到一個文檔,包含當前文檔的一個歸檔鏈接 --> <link rel="archives" href="https://example.com/2003/05/" title="May 2003"> <!-- 鏈接到層次結構中的頂級資源 --> <link rel="index" href="https://example.com/" title="DeWitt Clinton"> <!-- 給出該文檔的起點 --> <link rel="start" href="https://example.com/photos/pattern_recognition_1_about/" title="Pattern Recognition 1"> <!-- 引導當前文檔的前述資源序列 --> <link rel="prev" href="https://example.com/opensearch/opensearch-and-openid-a-sure-way-to-get-my-attention/"
title="OpenSearch and OpenID? A sure way to get my attention."> <!-- 給出一個自我參考 - 當文檔有多個可能的參考時非常有用 --> <link rel="self" type="application/atom+xml" href="https://example.com/atomFeed.php?page=3"> <!-- 分別是在一系列文件中的第一個、下一個、上一個和最后一個 --> <link rel="first" href="https://example.com/atomFeed.php"> <link rel="next" href="https://example.com/atomFeed.php?page=4"> <link rel="previous" href="https://example.com/atomFeed.php?page=2"> <link rel="last" href="https://example.com/atomFeed.php?page=147"> <!-- 當使用第三方服務來維護 blog 時使用 --> <link rel="EditURI" href="https://example.com/xmlrpc.php?rsd" type="application/rsd+xml" title="RSD"> <!-- 當另一個 WordPress 博客鏈接到你的 WordPress 博客或文章時形成一個自動化的評論 --> <link rel="pingback" href="https://example.com/xmlrpc.php"> <!-- 當你在自己的頁面上鏈接到一個 url 時通知它 --> <link rel="webmention" href="https://example.com/webmention"> <!-- 加載一個外部的 HTML 文件到當前 HTML 文件中 --> <link rel="import" href="component.html"> <!-- 打開搜索 --> <link rel="search" href="/open-search.xml" type="application/opensearchdescription+xml" title="Search Title"> <!-- Feeds --> <link rel="alternate" href="https://feeds.feedburner.com/example" type="application/rss+xml" title="RSS"> <link rel="alternate" href="https://example.com/feed.atom" type="application/atom+xml" title="Atom 0.3"> <!-- 預取,預載,預瀏覽 --> <link rel="dns-prefetch" href="//example.com/"> <link rel="preconnect" href="https://www.example.com/"> <link rel="prefetch" href="https://www.example.com/"> <link rel="prerender" href="https://example.com/"> <link rel="preload" href="image.png" as="image"> <!-- 更多信息:https://css-tricks.com/prefetching-preloading-prebrowsing/ -->
rss訂閱
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 -->
不推薦的link標簽
以下是不推薦使用的鏈接關系:
<link rel="shortcut icon" href="path/to/favicon.ico"> <!-- 沒有用的, 專有的和錯誤的, 詳見
https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/Y_2eFRh9BOs/gULYapoRBwAJ --> <link rel="subresource" href="styles.css">
favicon 圖標
IE 11, Chrome, Firefox, Safari, Opera支持<link>形式設置:
<link rel="icon" href="path/to/favicon-16.png" sizes="16x16" type="image/png"> <link rel="icon" href="path/to/favicon-32.png" sizes="32x32" type="image/png"> <link rel="icon" href="path/to/favicon-48.png" sizes="48x48" type="image/png"> <link rel="icon" href="path/to/favicon-62.png" sizes="62x62" type="image/png"> <link rel="icon" href="path/to/favicon-192.png" sizes="192x192" type="image/png">
注意:對於IE 10及以下版本不支持<link>形式設置,只通過將命名為favicon.ico的文件放置在網站根目錄中實現。
瀏覽器及平台詳細說明
QQ 瀏覽器(X5 內核)
QQ 瀏覽器(X5 內核)同樣適用於微信,QQ等第三方應用頁面開發。
<!-- 設置鎖定橫屏、豎屏顯示模式,portrait(橫屏),landscape(豎屏)--> <meta name="x5-orientation" content="portrait|landscape"> <!-- 設置全屏顯示頁面 --> <meta name="x5-fullscreen" content="true"> <!-- 開啟頁面以應用模式顯示(全屏顯示等) --> <meta name="x5-page-mode" content="app">
360瀏覽器
設置 360 瀏覽器渲染模式:webkit 為極速內核,ie-comp 為 IE 兼容內核,ie-stand 為 IE 標准內核。
<meta name="renderer" content="webkit|ie-comp|ie-stand">
360 瀏覽器就會在讀取到這個標簽后,立即切換對應的極速核。 另外為了保險起見再加入
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
這樣寫可以達到的效果是如果安裝了 Google Chrome Frame,則使用 GCF 來渲染頁面,如果沒有安裝 GCF,則使用最高版本的 IE 內核進行渲染。
UC 瀏覽器
設置屏幕方向
portrait 為橫屏,landscape 為豎屏。
<meta name="screen-orientation" content="portrait|landscape">
設置全屏
<meta name="full-screen" content="yes">
設置適應屏幕排版(縮放是否顯示滾動條)
UC 瀏覽器在標准排版效果實現的基礎上,提供適應屏幕的排版方式,當設置為 uc-fitscreen=yes,頁面進行縮放操作時,僅放大圖片和文字等元素,但不放大屏幕寬度,保持不出現水平(橫向)滾動條。
<meta name="viewport" content="uc-fitscreen=no|yes">
排版模式
UC 瀏覽器提供兩種排版模式,分別是適屏模式(fitscreen)及標准模式(standard),其中適屏模式簡化了一些頁面的處理,使得頁面內容更適合進行頁面閱讀、節省流量及響應更快,而標准模式則能按照標准規范對頁面進行排版及渲染。
<meta name="layoutmode" content="fitscreen|standard">
夜間模式
可以幫助用戶在低亮度或黑暗情況下更舒適的進行頁面瀏覽。由於基於網頁的應用愈加復雜,由瀏覽器實現的單一夜間模式不一定能夠適應所有情況(例如游戲應用),因此 UC 瀏覽器允許網頁設計者對其設計的頁面禁用瀏覽器的夜間模式,自行設計更適合用戶使用的夜間模式。
注意:頁面內的 frame/iframe 中的夜間模式的 meta 不生效。
<meta name="nightmode" content="enable|disable">
整頁圖片強制顯示
為了節省流量及加快速度,UC 為用戶提供了無圖模式,在實際使用中存在頁面中的圖片是不可缺少的,例如驗證碼,地圖等。通過強制圖片顯示的功能可以保證圖片顯示不受用戶的設置影響。
**注意:整頁圖片強制顯示僅對當前頁面生效,對頁面內的 frame/iframe 不生效,也不影響前進后退的頁面
<meta name="imagemode" content="force">
開啟應用模式
<meta name="browsermode" content="application">
應用模式是為方便 Web 應用及游戲開發者設置的綜合開關,通過meta標簽進行指示打開,當進入應用模式時,瀏覽器將自動調整以下參數:
| 參數 | 狀態 | 說明 |
|---|---|---|
| 全屏 | 生效 | 可通過 meta 或 JS API 調用退出全屏 |
| 長按菜單 | 失效 | 可通過 JS API 調用重新生效 |
| 瀏覽器默認手勢 | 失效 | 可通過 JS API 調用重新生效 |
| 排版模式 | 標准模式 | 可通過 meta 或 JS API 調用設置其他排版模式 |
| 強制圖片顯示 | 生效 | / |
| 夜間模式 | 失效 | 可通過 meta 或 JS API 調用啟用夜間模式 |
縮放字體
例如:禁用的 UC 瀏覽器的字體縮放功能
<meta name="wap-font-scale" content="no">
Apple iOS原生瀏覽器
添加智能 App 廣告條
告訴瀏覽器這個網站對應的app,並在頁面上顯示下載banner,需要注意的是Smart App Banners標簽不能用在frame框架內部,否則不起作用。
其中app-id(必須), affiliate-data (可選), app-argument (可選)
<meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">
例如Digg的寫法:
<meta name="apple-itunes-app" content="app-id=362872995, affiliate-data=bevbOqLt02I, app-argument=digg://">
忽略數字自動識別為電話號碼
<meta name="format-detection" content="telephone=no">
啟用 WebApp 全屏模式
<meta name="apple-mobile-web-app-capable" content="yes">
添加到主屏后設置狀態欄的背景顏色
<meta name="apple-mobile-web-app-status-bar-style" content="black">
只有在 “apple-mobile-web-app-capable” content=”yes” 時生效。
- 如果設置為 default 或 black ,網頁內容從狀態欄底部開始。
- 如果設置為 black-translucent ,網頁內容充滿整個屏幕,頂部會被狀態欄遮擋。
添加到主屏后的標題(iOS 6 新增)
<meta name="apple-mobile-web-app-title" content="App Title">
iOS 圖標
圖片自動處理成圓角和高光等效果。
<link rel="apple-touch-icon" href="path/to/apple-touch-icon.png">
禁止系統自動添加效果,直接顯示設計原圖。
<link rel="apple-touch-icon-precomposed" href="path/to/apple-touch-icon-precomposed.png">
iOS 8+ 不再支持 precomposed, 只有 apple-touch-icon 是必須的
在大多數情況下,在head中一個180×180px的圖標就足夠了。如果您想要由設備確定的唯一圖標,請使用不同大小的圖標。
<link rel="apple-touch-icon" sizes="57x57" href="path/to/icon@57.png"> <link rel="apple-touch-icon" sizes="72x72" href="path/to/icon@72.png"> <link rel="apple-touch-icon" sizes="114x114" href="path/to/icon@114.png"> <link rel="apple-touch-icon" sizes="144x144" href="path/to/icon@144.png">
啟動畫面 ( 不贊成使用 )
iPad 的啟動畫面是不包括狀態欄區域的,iPhone 和 iPod touch 的啟動畫面是包含狀態欄區域的
<link rel="apple-touch-startup-image" href="path/to/startup.png">
iOS 應用深度鏈接
<meta name="apple-itunes-app" content="app-id=APP-ID, app-argument=http/url-sample.com"> <link rel="alternate" href="ios-app://APP-ID/http/url-sample.com">
Google Android原生瀏覽器
標簽頁選項卡顏色
Android Lollipop 中的 Chrome 39 增加 theme-color meta 標簽,用來控制選項卡顏色。
<meta name="theme-color" content="#db5945">
添加到主屏
<!-- 添加到主屏 --> <meta name="mobile-web-app-capable" content="yes">
安卓應用深度鏈接(網頁上喚起應用)
<!-- Android app deep linking --> <meta name="google-play-app" content="app-id=package-name"> <link rel="alternate" href="android-app://package-name/http/url-sample.com">
注:貌似沒測試成功,如果你知道如何正確設置,歡迎留言斧正。
Apple Safari 瀏覽器
Safari 10開始支持固定書簽頁的SVG favicons了,你可以這樣使用:
<!-- Pinned Site --> <link rel="mask-icon" href="path/to/icon.svg" color="red">
類似的效果
Google Chrome瀏覽器
關閉chrome瀏覽器下翻譯插件
有些時候感覺chrome瀏覽器下翻譯插件很煩人,可以通過下面的代碼禁用它。
<meta name="google" value="notranslate" />
chrome瀏覽器插件安裝
有時候,你需要在你的頁面上點擊某個安卓,直接安卓你的chrome瀏覽器插件,而不是鏈接到Chrome webstore 的詳細地址再安裝,那么你可以使用:
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/APP_ID">
Google Chrome Mobile (只針對 Android)
從 Chrome 31 開始,你可以設置你的 Web 應用為“app mode”,如 Safari。
<!-- 鏈接到一個 manifest 並定義 manifest 的元數據。--> <!-- manifest.json 中的例子也可以通過以下鏈接找到。--> <link rel="manifest" href="manifest.json"> <!-- 定義你的網頁為 Web 應用 --> <meta name="mobile-web-app-capable" content="yes"> <!-- 第一個是官方推薦格式。--> <link rel="icon" sizes="192x192" href="nice-highres.png"> <link rel="icon" sizes="128x128" href="niceicon.png"> <!-- 所有帶 apple 前綴的格式已廢棄,所以不要使用它們。--> <link rel="apple-touch-icon" sizes="128x128" href="niceicon.png"> <link rel="apple-touch-icon-precomposed" sizes="128x128" href="niceicon.png">
Internet Explorer瀏覽器
模式設置
//IE8以下以IE7標准模式呈現網頁,而IE9則以IE9的標准模式呈現網頁:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9"> //如果安裝了GCF,則使用GCF來渲染頁面("chrome=1"), //如果沒有安裝GCF,則使用最高版本的IE內核進行渲染("IE=edge") <meta http-equiv="x-ua-compatible" content="ie=edge">
win8,win10下的一些設置
<meta http-equiv="cleartype" content="on"> <meta name="skype_toolbar" content="skype_toolbar_parser_compatible"> <!-- Disable link highlighting on IE 10 on Windows Phone 具體說明查看:
https://blogs.windows.com/buildingapps/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10/--> <meta name="msapplication-tap-highlight" content="no"> <!-- Pinned sites 具體說明查看:https://msdn.microsoft.com/en-us/library/dn255024(v=vs.85).aspx--> <meta name="application-name" content="Contoso Pinned Site Caption"> <meta name="msapplication-tooltip" content="Example Tooltip Text"> <meta name="msapplication-starturl" content="/"> <meta name="msapplication-config" content="http://example.com/browserconfig.xml"> <meta name="msapplication-allowDomainApiCalls" content="true"> <meta name="msapplication-allowDomainMetaTags" content="true"> <meta name="msapplication-badge" content="frequency=30; polling-uri=http://example.com/id45453245/polling.xml"> <meta name="msapplication-navbutton-color" content="#FF3300"> <meta name="msapplication-notification" content="frequency=60;polling-uri=http://example.com/livetile"> <meta name="msapplication-square150x150logo" content="path/to/logo.png"> <meta name="msapplication-square310x310logo" content="path/to/largelogo.png"> <meta name="msapplication-square70x70logo" content="path/to/tinylogo.png"> <meta name="msapplication-wide310x150logo" content="path/to/widelogo.png"> <meta name="msapplication-task"
content="name=Check Order Status;action-uri=./orderStatus.aspx?src=IE9;icon-uri=./favicon.ico"> <meta name="msapplication-task-separator" content="1"> //Windows 8 磁貼顏色 <meta name="msapplication-TileColor" content="#FF3300"> //Windows 8 磁貼圖標 <meta name="msapplication-TileImage" content="path/to/tileimage.jpg"> <meta name="msapplication-window" content="width=1024;height=768">
APP 鏈接
<!-- iOS --> <meta property="al:ios:url" content="applinks://docs"> <meta property="al:ios:app_store_id" content="12345"> <meta property="al:ios:app_name" content="App Links"> <!-- Android --> <meta property="al:android:url" content="applinks://docs"> <meta property="al:android:app_name" content="App Links"> <meta property="al:android:package" content="org.applinks"> <!-- Web Fallback --> <meta property="al:web:url" content="http://applinks.org/documentation"> <!-- More info: http://applinks.org/documentation/ -->
敬請指正補充!
(未完待續~~)
