其他

HTML <head> 标签大全

2017-09-27 译者:Amery2010 Linux中国
一份关于任何可以写入到你的文档中<head>部分的清单。
-- Joshbuchea


本文导航
编译自 | https://github.com/joshbuchea/HEAD 
 作者 | Joshbuchea
转载自 | https://github.com/Amery2010/HEAD 
 译者 | Amery2010


一份关于任何可以写入到你的文档中 <head> 部分的清单。

最小推荐

下面是基本的、最低限度的网站基本标签:

  1. <meta charset="utf-8">

  2. <meta http-equiv="x-ua-compatible" content="ie=edge">

  3. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  4. <!-- 以上 3 个 meta 标签 *必须* 放在 head 的最前面;其他任何的 head 内容必须在这些标签的 *后面* -->

  5. <title>页面标题</title>

网页元素

  1. <!-- 文档标题 -->

  2. <title>页面标题</title>

  3. <!-- 基本 URL 作用于文档中所包含的所有相对 URL -->

  4. <base href="https://example.com/page.html">

  5. <!-- 外部的 CSS -->

  6. <link rel="stylesheet" href="styles.css">

  7. <!-- 文档内的 CSS -->

  8. <style>

  9.  /* ... */

  10. </style>

  11. <!-- JavaScript -->

  12. <script src="script.js"></script>

  13. <noscript><!--无 JS 时的替代--></noscript>

Meta 标签

  1. <!-- 设置文档的字符编码 -->

  2. <meta charset="utf-8">

  3. <meta http-equiv="x-ua-compatible" content="ie=edge">

  4. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  5. <!-- 以上 3 个 meta 标签 *必须* 放在 head 的最前面;其他任何的 head 内容必须在这些标签的 *后面* -->

  6. <!-- 允许控制资源的过度加载 -->

  7. <meta http-equiv="Content-Security-Policy" content="default-src 'self'">

  8. <!-- 尽早地放置在文档中 -->

  9. <!-- 仅应用于该标签下的内容 -->

  10. <!-- Web 应用的名称(仅当网站被用作为一个应用时才使用)-->

  11. <meta name="application-name" content="应用名称">

  12. <!-- 针对页面的简短描述(限制 150 字符)-->

  13. <!-- 在*某些*情况下,该描述是被用作搜索结果展示片段的一部分 -->

  14. <meta name="description" content="一个页面描述">

  15. <!-- 控制搜索引擎的抓取和索引行为 -->

  16. <meta name="robots" content="index,follow"><!-- 所有搜索引擎 -->

  17. <meta name="googlebot" content="index,follow"><!-- 仅对 Google 有效 -->

  18. <!-- 告诉 Google 不显示网站链接的搜索框 -->

  19. <meta name="google" content="nositelinkssearchbox">

  20. <!-- 告诉 Google 不提供此页面的翻译 -->

  21. <meta name="google" content="notranslate">

  22. <!-- 验证 Google 搜索控制台的所有权 -->

  23. <meta name="google-site-verification" content="verification_token">

  24. <!-- 验证 Yandex 网站管理员的所有权 -->

  25. <meta name="yandex-verification" content="verification_token">

  26. <!-- 验证 Bing 网站管理员中心的所有权 -->

  27. <meta name="msvalidate.01" content="verification_token">

  28. <!-- 验证 Alexa 控制台的所有权 -->

  29. <meta name="alexaVerifyID" content="verification_token">

  30. <!-- 验证 Pinterest 控制台的所有权 -->

  31. <meta name="p:domain_verify" content="code from pinterest">

  32. <!-- 验证 Norton 安全站点的所有权 -->

  33. <meta name="norton-safeweb-site-verification" content="norton code">

  34. <!-- 用来命名软件或用于构建网页(如 - WordPress、Dreamweaver)-->

  35. <meta name="generator" content="program">

  36. <!-- 关于你的网站主题的简短描述 -->

  37. <meta name="subject" content="你的网站主题">

  38. <!-- 基于网站内容给出一般的年龄分级 -->

  39. <meta name="rating" content="General">

  40. <!-- 允许控制 referrer 信息如何传递 -->

  41. <meta name="referrer" content="no-referrer">

  42. <!-- 禁用自动检测和格式化可能的电话号码 -->

  43. <meta name="format-detection" content="telephone=no">

  44. <!-- 通过设置为 “off” 完全退出 DNS 预取 -->

  45. <meta http-equiv="x-dns-prefetch-control" content="off">

  46. <!-- 在客户端存储 cookie,web 浏览器的客户端识别 -->

  47. <meta http-equiv="set-cookie" content="name=value; expires=date; path=url">

  48. <!-- 指定要显示在一个特定框架中的页面 -->

  49. <meta http-equiv="Window-Target" content="_value">

  50. <!-- 地理标签 -->

  51. <meta name="ICBM" content="latitude, longitude">

  52. <meta name="geo.position" content="latitude;longitude">

  53. <meta name="geo.region" content="country[-state]"><!-- 国家代码 (ISO 3166-1): 强制性, 州代码 (ISO 3166-2): 可选; 如 content="US" / content="US-NY" -->

  54. <meta name="geo.placename" content="city/town"><!-- 如 content="New York City" -->


◈ Google 可以识别的 Meta 标签[1]
◈ WHATWG Wiki: Meta 拓展[2]
◈ ICBM - 维基百科[3]
◈ 地理标记 - 维基百科[4]


链接

  1. <!-- 表明一个 CSS 样式表 -->

  2. <link rel="stylesheet" href="https://example.com/styles.css">

  3. <!-- 有助于防止出现内容重复的问题 -->

  4. <link rel="canonical" href="https://example.com/2010/06/9-things-to-do-before-entering-social-media.html">

  5. <!-- 之前用于包含 icon 链接,但已被废弃并不再使用 -->

  6. <link rel="shortlink" href="https://example.com/?p=42">

  7. <!-- 链接到当前文档的一个 AMP HTML 版本 -->

  8. <link rel="amphtml" href="https://example.com/path/to/amp-version.html">

  9. <!-- 链接到一个指定 Web 应用程序“安装”证书的 JSON 文件 -->

  10. <link rel="manifest" href="manifest.json">

  11. <!-- 链接到文档的作者 -->

  12. <link rel="author" href="humans.txt">

  13. <!-- 指向一个适用于链接内容的版权申明 -->

  14. <link rel="license" href="copyright.html">

  15. <!-- 给出可能的你的另一种语言的文档位置参考 -->

  16. <link rel="alternate" href="https://es.example.com/" hreflang="es">

  17. <!-- 提供了关于作者或其他人的信息 -->

  18. <link rel="me" href="https://google.com/profiles/thenextweb" type="text/html">

  19. <link rel="me" href="mailto:name@example.com">

  20. <link rel="me" href="sms:+15035550125">

  21. <!-- 链接到一个描述历史记录、文档或其他具有历史意义的材料的集合的文档。 -->

  22. <link rel="archives" href="https://example.com/archives/">

  23. <!-- 链接到层次结构中的顶级资源 -->

  24. <link rel="index" href="https://example.com/">

  25. <!-- 给出一个自我参考 - 当文档有多个可能的参考时非常有用 -->

  26. <link rel="self" type="application/atom+xml" href="https://example.com/atomFeed.php?page=3">

  27. <!-- 分别是在一系列文件中的第一个、下一个、上一个和最后一个 -->

  28. <link rel="first" href="https://example.com/atomFeed.php">

  29. <link rel="next" href="https://example.com/atomFeed.php?page=4">

  30. <link rel="prev" href="https://example.com/atomFeed.php?page=2">

  31. <link rel="last" href="https://example.com/atomFeed.php?page=147">

  32. <!-- 当使用第三方服务来维护 blog 时使用 -->

  33. <link rel="EditURI" href="https://example.com/xmlrpc.php?rsd" type="application/rsd+xml" title="RSD">

  34. <!-- 当另一个 WordPress 博客链接到你的 WordPress 博客或文章时形成一个自动化的评论 -->

  35. <link rel="pingback" href="https://example.com/xmlrpc.php">

  36. <!-- 当你在自己的页面上链接到一个 url 时通知它 -->

  37. <link rel="webmention" href="https://example.com/webmention">

  38. <!-- 加载一个外部的 HTML 文件到当前 HTML 文件中 -->

  39. <link rel="import" href="/path/to/component.html">

  40. <!-- 打开搜索 -->

  41. <link rel="search" href="/open-search.xml" type="application/opensearchdescription+xml" title="Search Title">

  42. <!-- Feeds -->

  43. <link rel="alternate" href="https://feeds.feedburner.com/example" type="application/rss+xml" title="RSS">

  44. <link rel="alternate" href="https://example.com/feed.atom" type="application/atom+xml" title="Atom 0.3">

  45. <!-- 预取,预载,预浏览 -->

  46. <link rel="dns-prefetch" href="//example.com/">

  47. <link rel="preconnect" href="https://www.example.com/">

  48. <link rel="prefetch" href="https://www.example.com/">

  49. <link rel="prerender" href="https://example.com/">

  50. <link rel="preload" href="image.png" as="image">

  51. <!-- 更多信息:https://css-tricks.com/prefetching-preloading-prebrowsing/ -->

网站图标

  1. <!-- 针对 IE 10 及以下版本 -->

  2. <!-- 如果将 `favicon.ico` 放在根目录下,则无需标签 -->

  3. <!-- 对于 IE 11、Chrome、Firefox、Safari 和 Opera -->

  4. <link rel="icon" type="image/png" sizes="16x16" href="/path/to/favicon-16x16.png">

  5. <link rel="icon" type="image/png" sizes="32x32" href="/path/to/favicon-32x32.png">

  6. <link rel="icon" type="image/png" sizes="96x96" href="/path/to/favicon-96x96.png">

  7. <!-- 更多信息: https://bitsofco.de/all-about-favicons-and-touch-icons/ -->


◈ 所有关于网站图标(和触摸图标)的信息[5]
◈ 网站图标对照表[6]


社交

Facebook Open Graph

  1. <meta property="fb:app_id" content="123456789">

  2. <meta property="og:url" content="https://example.com/page.html">

  3. <meta property="og:type" content="website">

  4. <meta property="og:title" content="Content Title">

  5. <meta property="og:image" content="https://example.com/image.jpg">

  6. <meta property="og:description" content="Description Here">

  7. <meta property="og:site_name" content="Site Name">

  8. <meta property="og:locale" content="en_US">

  9. <meta property="article:author" content="">


◈ Facebook 的 Open Graph 的标记[7]
◈ Open Graph 协议[8]


Facebook Instant Articles

  1. <meta charset="utf-8">

  2. <meta property="op:markup_version" content="v1.0">

  3. <!-- 你的文章的 Web 版网址 -->

  4. <link rel="canonical" href="http://example.com/article.html">

  5. <!-- 用于该文章的样式 -->

  6. <meta property="fb:article_style" content="myarticlestyle">


◈ Facebook Instant Articles: 创建文章[9]
◈ Instant Articles: 格式参考[10]


Twitter Cards

  1. <meta name="twitter:card" content="summary">

  2. <meta name="twitter:site" content="@site_account">

  3. <meta name="twitter:creator" content="@individual_account">

  4. <meta name="twitter:url" content="https://example.com/page.html">

  5. <meta name="twitter:title" content="Content Title">

  6. <meta name="twitter:description" content="Content description less than 200 characters">

  7. <meta name="twitter:image" content="https://example.com/image.jpg">


◈ Twitter 名片:入门指南[11]
◈ Twitter 名片验证[12]


Google+ / Schema.org

  1. <link href="https://plus.google.com/+YourPage" rel="publisher">

  2. <meta itemprop="name" content="内容标题">

  3. <meta itemprop="description" content="内容描述少于 200 个字符">

  4. <meta itemprop="image" content="https://example.com/image.jpg">

Pinterest

根据他们的帮助中心[13]可知,Pinterest 允许你禁止他人保存你网站里的内容。description 为可选。

  1. <meta name="pinterest" content="nopin" description="Sorry, you can't save from my website!">

OEmbed

  1. <link rel="alternate" type="application/json+oembed"

  2.  href="http://example.com/services/oembed?url=http%3A%2F%2Fexample.com%2Ffoo%2F&amp;format=json"

  3.  title="oEmbed Profile: JSON">

  4. <link rel="alternate" type="text/xml+oembed"

  5.  href="http://example.com/services/oembed?url=http%3A%2F%2Fexample.com%2Ffoo%2F&amp;format=xml"

  6.  title="oEmbed Profile: XML">


◈ oEmbed 格式[14]


浏览器 / 平台

Apple iOS

  1. <!-- 智能应用 Banner -->

  2. <meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">

  3. <!-- 禁用自动检测和格式化可能的电话号码 -->

  4. <meta name="format-detection" content="telephone=no">

  5. <!-- 添加到主屏幕 -->

  6. <meta name="apple-mobile-web-app-capable" content="yes">

  7. <meta name="apple-mobile-web-app-status-bar-style" content="black">

  8. <meta name="apple-mobile-web-app-title" content="应用标题">

  9. <!-- 触摸图标 -->

  10. <!-- 在大多数情况下,在 `<head>` 中,一个 180×180px 触摸图标就已经足够了 -->

  11. <link rel="apple-touch-icon" href="/path/to/apple-touch-icon.png">

  12. <!-- 注意:iOS 7 上的 Safari 不会对图标产生效果。 -->

  13. <!-- 较早版本的 Safari 不会对以 `-precomposed.png` 后缀命名的图标文件产生效果。 -->

  14. <!-- 启动画面(已无效) -->

  15. <link rel="apple-touch-startup-image" href="path/to/startup.png">

  16. <!-- iOS 应用深层链接 -->

  17. <meta name="apple-itunes-app" content="app-id=APP-ID, app-argument=http/url-sample.com">

  18. <link rel="alternate" href="ios-app://APP-ID/http/url-sample.com">


◈ Apple Meta 标签[15]


Apple Safari

  1. <!-- 固定网站 -->

  2. <link rel="mask-icon" href="path/to/icon.svg" color="red">

Google Android

  1. <meta name="theme-color" content="#E64545">

  2. <!-- 添加到主屏幕 -->

  3. <meta name="mobile-web-app-capable" content="yes">

  4. <!-- 更多信息:https://developer.chrome.com/multidevice/android/installtohomescreen -->

Google Chrome

  1. <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/APP_ID">

  2. <!-- 禁用翻译提示 -->

  3. <meta name="google" content="notranslate">

Google Chrome Mobile (只针对 Android)

从 Chrome 31 开始,你可以设置你的 Web 应用为“app mode”,如 Safari。

  1. <!-- 链接到一个 manifest 并定义 manifest 的元数据。-->

  2. <!-- manifest.json 中的例子也可以通过以下链接找到。-->

  3. <link rel="manifest" href="manifest.json">

  4. <!-- 定义你的网页为 Web 应用 -->

  5. <meta name="mobile-web-app-capable" content="yes">

  6. <!-- 主屏幕图标 -->

  7. <link rel="icon" sizes="192x192" href="highres-icon.png">


◈ Google 开发者[16]


Microsoft Internet Explorer

  1. <meta http-equiv="x-ua-compatible" content="ie=edge">

  2. <meta name="skype_toolbar" content="skype_toolbar_parser_compatible">

  3. <!-- IE10: 禁用链接点击高亮 (https://blogs.windows.com/buildingapps/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10/) -->

  4. <meta name="msapplication-tap-highlight" content="no">

  5. <!-- 固定网站 (https://msdn.microsoft.com/en-us/library/dn255024(v=vs.85).aspx) -->

  6. <meta name="application-name" content="Sample Title">

  7. <meta name="msapplication-tooltip" content="A description of what this site does.">

  8. <meta name="msapplication-starturl" content="http://example.com/index.html?pinned=true">

  9. <meta name="msapplication-navbutton-color" content="#FF3300">

  10. <meta name="msapplication-window" content="width=800;height=600">

  11. <meta name="msapplication-task" content="name=Task 1;action-uri=http://host/Page1.html;icon-uri=http://host/icon1.ico">

  12. <meta name="msapplication-task" content="name=Task 2;action-uri=http://microsoft.com/Page2.html;icon-uri=http://host/icon2.ico">

  13. <meta name="msapplication-badge" value="frequency=NUMBER_IN_MINUTES;polling-uri=http://example.com/path/to/file.xml">

  14. <meta name="msapplication-TileColor" content="#FF3300">

  15. <meta name="msapplication-TileImage" content="path/to/tileimage.jpg">

  16. <meta name="msapplication-config" content="http://example.com/browserconfig.xml">

  17. <meta name="msapplication-notification" content="frequency=60;polling-uri=http://example.com/livetile;polling-uri2=http://example.com/livetile2">

  18. <meta name="msapplication-task-separator" content="1">

应用链接

  1. <!-- iOS -->

  2. <meta property="al:ios:url" content="applinks://docs">

  3. <meta property="al:ios:app_store_id" content="12345">

  4. <meta property="al:ios:app_name" content="App Links">

  5. <!-- Android -->

  6. <meta property="al:android:url" content="applinks://docs">

  7. <meta property="al:android:app_name" content="App Links">

  8. <meta property="al:android:package" content="org.applinks">

  9. <!-- Web 回退 -->

  10. <meta property="al:web:url" content="http://applinks.org/documentation">

  11. <!-- 更多信息:http://applinks.org/documentation/ -->


◈ 应用链接文档[17]


国内的浏览器

360 浏览器

  1. <!-- 选择渲染引擎 -->

  2. <meta name="renderer" content="webkit|ie-comp|ie-stand">

QQ 移动浏览器

  1. <!-- 在指定方向上锁定屏幕(锁定横/竖屏) -->

  2. <meta name="x5-orientation" content="landscape/portrait">

  3. <!-- 全屏显示此页面 -->

  4. <meta name="x5-fullscreen" content="true">

  5. <!-- 页面将以“应用模式”显示(全屏等)-->

  6. <meta name="x5-page-mode" content="app">

UC 移动浏览器

  1. <!-- 在指定方向上锁定屏幕(锁定横/竖屏) -->

  2. <meta name="screen-orientation" content="landscape/portrait">

  3. <!-- 全屏显示此页面 -->

  4. <meta name="full-screen" content="yes">

  5. <!-- 即使在“文本模式”下,UC 浏览器也会显示图片 -->

  6. <meta name="imagemode" content="force">

  7. <!-- 页面将以“应用模式”显示(全屏、禁止手势等) -->

  8. <meta name="browsermode" content="application">

  9. <!-- 在此页面禁用 UC 浏览器的“夜间模式” -->

  10. <meta name="nightmode" content="disable">

  11. <!-- 简化页面,减少数据传输 -->

  12. <meta name="layoutmode" content="fitscreen">

  13. <!-- 禁用的 UC 浏览器的功能,“当此页面中有较多文本时缩放字体” -->

  14. <meta name="wap-font-scale" content="no">


◈ UC 浏览器文档[18]


注意

性能

当启用 GZIP 时,移动 href 属性到该元素的开头以提高压缩,因为 href 属性被用于 abase 和 link 标签。

示例:

  1. <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">

其他资源


◈ HTML5 样板文档:HTML 标签[19]
◈ HTML5 样板文档:扩展和定制[20]


相关项目


◈ Atom HTML Head 片段[21] - Atom HEAD 片段包
◈ Sublime Text HTML Head 片段[22] - Sublime Text HEAD 片段包
◈ head-it[23] - HEAD 片段的 CLI 接口
◈ vue-head[24] - 在 Vue.js 中操作 HEAD 标签的 meta 信息


其他格式


◈ PDF[25]


翻译


◈ 英语/English[26]
◈ 巴西葡萄牙语/Brazilian Portuguese[27]
◈ 意大利语/Italian[28]
◈ 日语/Japanese[29]
◈ 俄罗斯语/Russian/Русский[30]
◈ 土耳其语/Turkish/Türkçe[31]
◈ 韩语/Korean[32]


贡献

开启一个 issue 或一个 pull 请求来提出修改或补充。

指南

HEAD 仓库由两个分支组成:

1、master

对该分支包含的 README.md 文件的修改会自动反映在 <Head> Cheat Sheet[33] 网站上。 所有对照表内容的更改都应该针对此文件。

请按照下列步骤 pull 请求:


◈ 只修改一个标签,或一次一组相关的标签
◈ 对属性使用双引号
◈ 请不要在自我闭合的元素中使用斜线 —— 即便 HTML5 规范中说,他们是可选的
◈ 考虑在文档中加入链接以支持你所提到的变化


2. gh-pages

该分支负责 <Head> Cheat Sheet[34] 网站。我们使用 Jekyll[35] 通过 GitHub Pages[36]服务来部署 README.md Markdown 文件。所有网站相关的修改必须集中在这里。

你可能需要通过 Jekyll 文档[37] 来了解 Jekyll 是如何在该分支上工作的。

贡献者

列出所有超级棒的 贡献者们[38].

作者

Josh Buchea[39]

翻译者

子丶言[40]

协议

CC0,在法律范围内,Josh Buchea 已经放弃了这项工作的所有版权以及相关或邻近的权利。


推荐文章

< 左右滑动查看相关文章 >

点击图片、输入文章 ID 或识别二维码直达



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存