Image placeholder

最全HTML <head>标签文档配置列表

Image placeholder
F2EX 2016-12-27

一个可包含在 <head> 文档中的所有内容的列表,包含常用 META ,LINK , Elements , Favicons 还有专门针对国内浏览器的写法。

推荐的最少写法

以下是网站的基本标签:

<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个元标记必须在最上面,任何其他头部内容必须在这些标签后 -->
<title>Page Title</title>

元素 标记

<!-- 文档标题 -->
<title>Page Title</title>

<!-- 用于文档中包含的所有相关 URL 的基本 URL  -->
<base href="https://example.com/page.html">

<!-- 外联 CSS -->
<link rel="stylesheet" href="styles.css">

<!-- 嵌入式 CSS -->
<style>
  /* ... */
</style>

<!-- JavaScript -->
<script src="script.js"></script>
<noscript><!--没有 JS 的选择--></noscript>

Meta 标记

<meta charset="utf-8"> <!-- 设置文档的字符编码 -->
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- 上述3个元标记必须在最上面,任何其他头部内容必须在这些标签后 -->

<!-- 允许控制从哪里加载资源 -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<!-- 尽早在文件中放置 -->
<!-- 仅适用于此标签下方的内容 -->

<!-- Web应用程序的名称(仅当该网站用作应用程序时才应使用) -->
<meta name="application-name" content="Application Name">

<!-- 页面简短说明(限150个字符) -->
<!-- 在*某些*情况下,此描述用作搜索结果中显示的片段的一部分。 -->
<meta name="description" content="A description of the page">

<!-- 控制搜索引擎抓取和索引的行为 -->
<meta name="robots" content="index,follow,noodp"><!-- 所有搜索引擎 -->
<meta name="googlebot" content="index,follow"><!-- Google 搜索 -->

<!-- 告诉 Google 不要显示附加链接搜索框 -->
<meta name="google" content="nositelinkssearchbox">

<!-- 告诉 Google 不要为此页面提供翻译 -->
<meta name="google" content="notranslate">

<!-- 验证 Google Search Console 的所有权 -->
<meta name="google-site-verification" content="verification_token">

<!-- 用于命名用于构建网站的软件(即 - WordPress,Dreamweaver) -->
<meta name="generator" content="program">

<!-- 您网站主题的简短描述 -->
<meta name="subject" content="your website's subject">

<!-- 简短的(10个字以内)描述。 主要用于学术论文 -->
<meta name="abstract" content="">

<!-- 完整的域名或网址 -->
<meta name="url" content="https://example.com/">

<meta name="directory" content="submission">

<!-- 根据网站内容提供年龄评级 -->
<meta name="rating" content="General">

<!-- 允许控制引荐来源网址信息的传递 -->
<meta name="referrer" content="no-referrer">

<!-- 禁用自动检测和格式化可能的电话号码 -->
<meta name="format-detection" content="telephone=no">

<!-- 通过设置为“关闭”完全退出 DNS 预取 -->
<meta http-equiv="x-dns-prefetch-control" content="off">

<!-- 在客户端 Web 浏览器上存储 cookie 以进行客户端标识 -->
<meta http-equiv="set-cookie" content="name=value; expires=date; path=url">

<!-- 指定页面显示在特定的框架中 -->
<meta http-equiv="Window-Target" content="_value">

<!-- 地理标签 -->
<meta name="ICBM" content="latitude, longitude">
<meta name="geo.position" content="latitude;longitude">
<meta name="geo.region" content="country[-state]"><!-- 国家代码 (ISO 3166-1): 强制, 状态码 (ISO 3166-2): 可选; 例如: content="US" / content="US-NY" -->
<meta name="geo.placename" content="city/town"><!-- 例如: content="New York City" -->

LINK 标记

<!-- 有助于防止重复的内容问题 -->
<link rel="canonical" href="https://example.com/2010/06/9-things-to-do-before-entering-social-media.html">

<!-- 用于包含在图标链接之前,但已被弃用,不再使用 -->
<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">

<!-- 指向 JSON 文件的链接,指定 Web 应用程序的“安装”凭据 -->
<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:[email protected]">
<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">

<!-- 在使用第三方服务来维护博客时使用 -->
<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">

<!-- 当你链接到你的网站时通知网址 -->
<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/ -->

Favicons 图标标记

<!-- For IE 10 and below -->
<!-- 没有链接,只需在根目录中放置一个名为 favicon.ico 的文件 -->

<!-- 适用于IE 11,Chrome,Firefox,Safari,Opera -->
<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">
<!-- 更多信息: https://bitsofco.de/all-about-favicons-and-touch-icons/ -->

社会化分享标记

Facebook / Open Graph
<meta property="fb:app_id" content="123456789">
<meta property="og:url" content="https://example.com/page.html">
<meta property="og:type" content="website">
<meta property="og:title" content="Content Title">
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:description" content="Description Here">
<meta property="og:site_name" content="Site Name">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="">
<!-- Facebook: https://developers.facebook.com/docs/sharing/webmasters#markup -->
<!-- Open Graph: http://ogp.me/ -->
Facebook / Instant Articles
<meta charset="utf-8">
<meta property="op:markup_version" content="v1.0">

<!-- 您的文章的网络版本的URL -->
<link rel="canonical" href="http://example.com/article.html">

<!-- 用于本文的风格 -->
<meta property="fb:article_style" content="myarticlestyle">
Twitter
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@site_account">
<meta name="twitter:creator" content="@individual_account">
<meta name="twitter:url" content="https://example.com/page.html">
<meta name="twitter:title" content="Content Title">
<meta name="twitter:description" content="Content description less than 200 characters">
<meta name="twitter:image" content="https://example.com/image.jpg">
<!-- 更多信息: https://dev.twitter.com/cards/getting-started -->
<!-- 验证: https://dev.twitter.com/docs/cards/validation/validator -->
Google+ / Schema.org
<link href="https://plus.google.com/+YourPage" rel="publisher">
<meta itemprop="name" content="Content Title">
<meta itemprop="description" content="Content description less than 200 characters">
<meta itemprop="image" content="https://example.com/image.jpg">
Pinterest
<meta name="pinterest" content="nopin" description="Sorry, you can't save from my website!">
OEmbed
<link rel="alternate" type="application/json+oembed"
  href="http://example.com/services/oembed?url=http%3A%2F%2Fexample.com%2Ffoo%2F&amp;format=json"
  title="oEmbed Profile: JSON">
<link rel="alternate" type="text/xml+oembed"
  href="http://example.com/services/oembed?url=http%3A%2F%2Fexample.com%2Ffoo%2F&amp;format=xml"
  title="oEmbed Profile: XML">

浏览器/平台

Apple iOS
<!-- app 横幅 -->
<meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">

<!-- 禁用自动检测和格式化可能的电话号码 -->
<meta name="format-detection" content="telephone=no">

<!-- 添加到主屏幕 -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="App Title">

<!-- 触摸图标 -->
<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+ 不再支持预先配置,只需要 Apple-touch-icon 即可 -->

<!-- 在大多数情况下,一个 180×180px 的触摸图标在头部就足够了 -->
<!-- 如果你想要独特的图标,则使用不同的图标大小 -->
<!-- determined by device. -->
<link rel="apple-touch-icon" sizes="57x57" href="path/to/[email protected]">
<link rel="apple-touch-icon" sizes="72x72" href="path/to/[email protected]">
<link rel="apple-touch-icon" sizes="114x114" href="path/to/[email protected]">
<link rel="apple-touch-icon" sizes="144x144" href="path/to/[email protected]">

<!-- 启动图像(已弃用) -->
<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">
Apple Safari
<!-- 固定网站 -->
<link rel="mask-icon" href="path/to/icon.svg" color="red">
Google Android
<meta name="theme-color" content="#E64545">

<!-- 添加到主屏幕 -->
<meta name="mobile-web-app-capable" content="yes">
<!-- 更多信息: https://developer.chrome.com/multidevice/android/installtohomescreen -->

<!-- Android 应用程序深度链接 -->
<meta name="google-play-app" content="app-id=package-name">
<link rel="alternate" href="android-app://package-name/http/url-sample.com">
Google Chrome
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/APP_ID">

<!-- 禁用翻译提示 -->
<meta name="google" value="notranslate">
Google Chrome Mobile (只限Android)
<!-- 链接到清单并定义清单元数据。 -->
<!-- manifest.json 的例子可以在下面的链接中找到。 -->
<link rel="manifest" href="manifest.json">

<!-- 将你的网页定义为网络应用程序 -->
<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">
Microsoft Internet Explorer
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="cleartype" content="on">
<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">

<!-- 在 Windows Phone 上禁用IE 10上的链接突出显示 (https://blogs.windows.com/buildingapps/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10/) -->
<meta name="msapplication-tap-highlight" content="no">

<!-- 固定网站 (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">
<meta name="msapplication-TileColor" content="#FF3300">
<meta name="msapplication-TileImage" content="path/to/tileimage.jpg">
<meta name="msapplication-window" content="width=1024;height=768">

App Links

<!-- 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 回退 -->
<meta property="al:web:url" content="http://applinks.org/documentation">
<!-- 更多信息: http://applinks.org/documentation/ -->

国内浏览器

360 浏览器
<!-- 选择渲染引擎 -->
<meta name="renderer" content="webkit|ie-comp|ie-stand">
QQ 移动版浏览器
<!-- 将屏幕锁定到指定的方向 -->
<meta name="x5-orientation" content="landscape/portrait">
<!-- 以全屏显示此页面 -->
<meta name="x5-fullscreen" content="true">
<!-- 页面将显示在“应用程序模式”(全屏等)中 -->
<meta name="x5-page-mode" content="app">
UC 移动版浏览器
<!-- 将屏幕锁定到指定的方向 -->
<meta name="screen-orientation" content="landscape/portrait">
<!-- 以全屏显示此页面 -->
<meta name="full-screen" content="yes">
<!-- 即使在“文本模式”下,UC 浏览器也会显示图像 -->
<meta name="imagemode" content="force">
<!-- 页面将显示在“应用程序模式”(全屏,禁止手势等) -->
<meta name="browsermode" content="application">
<!-- 在此页面禁用 UC 浏览器的“夜间模式” -->
<meta name="nightmode" content="disable">
<!-- 简化页面以减少数据传输 -->
<meta name="layoutmode" content="fitscreen">
<!-- 禁用UC浏览器的功能“在此页面中有多个单词时缩放字体” -->
<meta name="wap-font-scale" content="no">

更多<head>标签文档


2017-09-11