HTML 中的 HEAD 配置清单

目录

基本标签
网页元素
Meta 标签
Link 链接
Icon 网站图标
浏览器 / 平台
    Apple iOS
    Apple Safari
    Google Android
    Google Chrome
    Google Chrome Mobile (只针对 Android)
    Microsoft Internet Explorer
国内的浏览器
    360 浏览器
    QQ 移动浏览器
    UC 移动浏览器

网站最基本的标签

<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 以上 3 个 meta 标签 *必须* 放在 head 的最前面;其他任何的 head 内容必须在这些标签的 *后面* -->
<title>页面标题</title>

网页元素

<!-- 文档标题 -->
<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 标签 *必须* 放在 head 的最前面;其他任何的 head 内容必须在这些标签的 *后面* -->

<!-- 允许控制资源的过度加载 -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<!-- 尽早地放置在文档中 -->
<!-- 仅应用于该标签下的内容 -->

<!-- Web 应用的名称(仅当网站被用作为一个应用时才使用)-->
<meta name="application-name" content="应用名称">

<!-- 针对页面的简短描述(限制 150 字符)-->
<!-- 在*某些*情况下,该描述是被用作搜索结果展示片段的一部分 -->
<meta name="description" content="一个页面描述">

<!-- 控制搜索引擎的抓取和索引行为 -->
<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 搜索控制台的所有权 -->
<meta name="google-site-verification" content="verification_token">

<!-- 用来命名软件或用于构建网页(如 - WordPress、Dreamweaver)-->
<meta name="generator" content="program">

<!-- 关于你的网站主题的简短描述 -->
<meta name="subject" content="你的网站主题">

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

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

<!-- 基于网站内容给出一般的年龄分级 -->
<meta name="rating" content="General">

<!-- 允许控制 referrer 信息如何传递 -->
<meta name="referrer" content="no-referrer">

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

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

<!-- 在客户端存储 cookie,web 浏览器的客户端识别 -->
<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/media.html">

<!-- 链接到当前文档的一个 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/2020/05/" title="May 2020">

<!-- 链接到层次结构中的顶级资源 -->
<link rel="index" href="https://example.com/" title="DeWitt Clinton">

<!-- 给出该文档的起点 -->
<link rel="start" href="https://example.com/photos/" title="">

<!-- 引导当前文档的前述资源序列 -->
<link rel="prev" href="https://example.com/search/" title="">

<!-- 给出一个自我参考 - 当文档有多个可能的参考时非常有用 -->
<link rel="self" type="application/atom+xml" href="https://example.com/search?page=1">

<!-- 分别是在一系列文件中的第一个、下一个、上一个和最后一个 -->
<link rel="first" href="https://example.com/list">
<link rel="next" href="https://example.com/list?page=4">
<link rel="previous" href="https://example.com/list?page=2">
<link rel="last" href="https://example.com/list?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://example.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">

Icon 网站图标

<!-- 对于 IE10 及以下 -->
<!-- 无链接,只需在根目录下放置名为 favicon.ico 的文件 -->

<!-- 对于 IE 11、Chrome、Firefox、Safari 和 Opera -->
<link rel="icon" href="path/favicon-16.png" sizes="16x16" type="image/png">
<link rel="icon" href="path/favicon-32.png" sizes="32x32" type="image/png">
<link rel="icon" href="path/favicon-48.png" sizes="48x48" type="image/png">
<link rel="icon" href="path/favicon-62.png" sizes="62x62" type="image/png">
<link rel="icon" href="path/favicon-192.png" sizes="192x192" type="image/png">

浏览器 / 平台

Apple iOS

<!-- 智能应用 Banner -->
<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="应用标题">

<!-- 触摸图标 -->
<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。-->
<!-- 在大多数情况下,在 `<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">

<!-- 启动画面(已无效) -->
<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">

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)

从 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">

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 上禁用链接高亮 -->
<meta name="msapplication-tap-highlight" content="no">

<!-- 固定网站 -->
<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">

应用链接

<!-- 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">

国内的浏览器

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">