HTML5 head 头标签使用大全

付费节点推荐


免费节点


节点使用教程


HTML的头部内容特别多,有针对SEO的头部信息,也有针对移动设备的头部信息。而且各个浏览器内核以及各个国内浏览器厂商都有些自己的标签元素,有很多差异性。移动端的工作已经越来越成为前端工作的重要内容,除了平常的项目开发,HTML 头部标签功能,特别是meta,link等标签的功能属性显得非常重要。这里整理了一份 <head> 部分的清单,让大家了解每个标签及相应属性的意义,写出满足自己需求的 <head> 头部标签,可以很有效的增强页面的可用性。

HTML基本的头部标签

下面是HTML基本的头部元素:

html 代码:
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset=“utf-8”>
  5. <meta http-equiv=“x-ua-compatible” content=“ie=edge”>
  6. <!–移动端的页面这个可以忽略,具体可以查看本文Internet Explorer浏览器部分–>
  7. <meta name=“viewport” content=“width=device-width, initial-scale=1”>
  8. <!–具体可以查看本文 为移动设备添加 viewport 部分–>
  9. <!– 以上 3 个 meta 标签 *必须* 放在 head 的最前面;其他任何的 head 内容必须在这些标签的 *后面* –>
  10. <title>页面标题</title>
  11. </head>

其中

html 代码:
  1. <meta http-equiv=“x-ua-compatible” content=“ie=edge”>

在桌面开发的时候可以让IE浏览器以最新的模式渲染页面,具体可以查看本文Internet Explorer浏览器部分。
如果你的页面确定只在桌面浏览器中运行,那么

html 代码:
  1. <meta name=“viewport” content=“width=device-width, initial-scale=1”>

也可以省略。

DOCTYPE

DOCTYPE(Document Type),该声明位于文档中最前面的位置,处于 html 标签之前,此标签告知浏览器文档使用哪种 HTML 或者 XHTML 规范。

使用 HTML5 doctype,不区分大小写。

html 代码:
  1. <!DOCTYPE html> <!– 使用 HTML5 doctype,不区分大小写 –>

charset

声明文档使用的字符编码,

html 代码:
  1. <meta charset=“utf-8”>

html5 之前网页中会这样写:

html 代码:
  1. <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>

这两个是等效的,具体可移步阅读:<meta charset='utf-8'> vs <meta http-equiv='Content-Type'>,所以建议使用较短的,易于记忆。

lang属性

更加标准的 lang 属性写法 http://zhi.hu/XyIa

简体中文

html 代码:
  1. <html lang=“zh-cmn-Hans”> <!– 更加标准的 lang 属性写法 http://zhi.hu/XyIa –>

繁体中文

html 代码:
  1. <html lang=“zh-cmn-Hant”> <!– 更加标准的 lang 属性写法 http://zhi.hu/XyIa –>

很少情况才需要加地区代码,通常是为了强调不同地区汉语使用差异,例如:

html 代码:
  1. <p lang=“zh-cmn-Hans”>
  2. <strong lang=“zh-cmn-Hans-CN”>菠萝</strong><strong lang=“zh-cmn-Hant-TW”>鳳梨</strong>其实是同一种水果。只是大陆和台湾称谓不同,且新加坡、马来西亚一带的称谓也是不同的,称之为<strong lang=“zh-cmn-Hans-SG”>黄梨</strong>
  3. </p>

为什么 lang="zh-cmn-Hans" 而不是我们通常写的 lang="zh-CN" 呢,请移步阅读: 页头部的声明应该是用 lang=”zh” 还是 lang=”zh-cn”。

Meta 标签

meta标签是HTML中head头部的一个辅助性标签,它位于HTML文档头部的 <head><title> 标记之间,它提供用户不可见的信息。虽然这部分信息用户不可见,但是其作用非常强大,特别是当今的前端开发工作中,设置合适的meta标签可以大大提升网站页面的可用性。

桌面端开发中,meta标签通常用来为搜索引擎优化(SEO)及 robots定义页面主题,或者是定义用户浏览器上的cookie;它可以用于鉴别作者,设定页面格式,标注内容提要和关键字;还可以设置页面使其可以根据你定义的时间间隔刷新自己,以及设置RASC内容等级,等等。

移动端开发中,meta标签除了桌面端中的功能设置外,还包括,比如viewport设置,添加到主屏幕图标,标签页颜色等等实用设置。具体可以看后面详细的介绍。

meta标签分类

meta标签根据属性的不同,可分为两大部分:http-equiv 和 name 属性。

http-equiv:相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助浏览器正确地显示网页内容。
name属性:主要用于描述网页,与之对应的属性值为content,content中的内容主要是便于浏览器,搜索引擎等机器人识别,等等。

推荐使用的meta标签

html 代码:
  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. <!– 允许控制资源的过度加载 –>
  8. <meta http-equiv=“Content-Security-Policy” content=“default-src ‘self'”>
  9. <!– 尽早地放置在文档中 –>
  10. <!– 仅应用于该标签下的内容 –>
  11.  
  12. <!– Web 应用的名称(仅当网站被用作为一个应用时才使用)–>
  13. <meta name=“application-name” content=“应用名称”>
  14.  
  15. <!– 针对页面的简短描述(限制 150 字符)–>
  16. <!– 在*某些*情况下,该描述是被用作搜索结果展示片段的一部分 –>
  17. <meta name=“description” content=“一个页面描述”>
  18.  
  19. <!– 控制搜索引擎的抓取和索引行为 –>
  20. <meta name=“robots” content=“index,follow,noodp”><!– 所有的搜索引擎 –>
  21. <meta name=“googlebot” content=“index,follow”><!– 仅对 Google 有效 –>
  22.  
  23. <!– 告诉 Google 不显示网站链接的搜索框 –>
  24. <meta name=“google” content=“nositelinkssearchbox”>
  25.  
  26. <!– 告诉 Google 不提供此页面的翻译 –>
  27. <meta name=“google” content=“notranslate”>
  28.  
  29. <!– 验证 Google 搜索控制台的所有权 –>
  30. <meta name=“google-site-verification” content=“verification_token”>
  31.  
  32. <!– 用来命名软件或用于构建网页(如 – WordPress、Dreamweaver)–>
  33. <meta name=“generator” content=“program”>
  34.  
  35. <!– 关于你的网站主题的简短描述 –>
  36. <meta name=“subject” content=“你的网站主题”>
  37.  
  38. <!– 非常简短(少于 10 个字)的描述。主要用于学术论文。–>
  39. <meta name=“abstract” content=“”>
  40.  
  41. <!– 完整的域名或网址 –>
  42. <meta name=“url” content=“https://example.com/”>
  43.  
  44. <meta name=“directory” content=“submission”>
  45.  
  46. <!– 基于网站内容给出一般的年龄分级 –>
  47. <meta name=“rating” content=“General”>
  48.  
  49. <!– 允许控制 referrer 信息如何传递 –>
  50. <meta name=“referrer” content=“never”>
  51.  
  52. <!– 禁用自动检测和格式化可能的电话号码 –>
  53. <meta name=“format-detection” content=“telephone=no”>
  54.  
  55. <!– 通过设置为 “off” 完全退出 DNS 预取 –>
  56. <meta http-equiv=“x-dns-prefetch-control” content=“off”>
  57.  
  58. <!– 在客户端存储 cookie,web 浏览器的客户端识别 –>
  59. <meta http-equiv=“set-cookie” content=“name=value; expires=date; path=url”>
  60.  
  61. <!– 指定要显示在一个特定框架中的页面 –>
  62. <meta http-equiv=“Window-Target” content=“_value”>
  63.  
  64. <!– 地理标签 –>
  65. <meta name=“ICBM” content=“latitude, longitude”>
  66. <meta name=“geo.position” content=“latitude;longitude”>
  67. <!– 国家代码 (ISO 3166-1): 强制性, 州代码 (ISO 3166-2): 可选; 如 content=”US” / content=”US-NY” –>
  68. <meta name=“geo.region” content=“country[-state]”>
  69. <!– 如 content=”New York City” –>
  70. <meta name=“geo.placename” content=“city/town”>

相关的详细说明请查看:

  • Google 可以识别的 Meta 标签
  • WHATWG Wiki: Meta 拓展
  • ICBM – 维基百科
  • 地理标记 – 维基百科

为移动设备添加 viewport

viewport 可以让布局在移动浏览器上显示的更好。 通常会写

html 代码:
  1. <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 –>

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 中已经删除),可以在页面加载时最小化上下状态栏。这是一个布尔值,可以直接这样写:
    html 代码:
    1. <meta name=“viewport” content=“width=device-width, initial-scale=1, minimal-ui”>

而如果你的网站不是响应式的,请不要使用 initial-scale 或者禁用缩放。

html 代码:
  1. <meta name=“viewport” content=“width=device-width,user-scalable=yes”>

相关链接:非响应式设计的viewport

适配 iPhone 6 和 iPhone 6plus 则需要写:

html 代码:
  1. <meta name=“viewport” content=“width=375”>
  2. <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 头部必须)
    html 代码:
    1. <title>your title</title>
  • 页面关键词 keywords
    html 代码:
    1. <meta name=“keywords” content=“your keywords”>
  • 页面描述内容 description
    html 代码:
    1. <meta name=“description” content=“your description”>
  • 定义网页作者 author
    html 代码:
    1. <meta name=“author” content=“author,email address”>
  • 定义网页搜索引擎索引方式,robotterms 是一组使用英文逗号「,」分割的值,通常有如下几种取值:none,noindex,nofollow,all,index和follow。
    html 代码:
    1. <meta name=“robots” content=“index,follow”>

相关链接:WEB1038 – 标记包含无效的值

百度禁止转码

通过百度手机打开网页时,百度可能会对你的网页进行转码,脱下你的衣服,往你的身上贴狗皮膏药的广告,为此可在 head 内添加

html 代码:
  1. <meta http-equiv=“Cache-Control” content=“no-siteapp” />

相关链接:SiteApp 转码声明

不推荐的 meta 属性

下面是不推荐使用的 meta 属性,因为它们采用率低,或已弃用:

html 代码:
  1. <!– 用于声明文档语言,但支持得不是很好。最好使用 <html lang=””> –>
  2. <meta name=“language” content=“en”>
  3.  
  4. <!– Google 无视 & Bing 认为垃圾的指示器 –>
  5. <meta name=“keywords” content=“你,关键字,在这里,不使用空格,而用逗号进行分隔”>
  6. <!– 目前没有在任何搜索引擎中使用过的声明 –>
  7. <meta name=“revised” content=“Sunday, July 18th, 2010, 5:15 pm”>
  8.  
  9. <!– 为垃圾邮件机器人收获 email 地址提供了一种简单的方式 –>
  10. <meta name=“reply-to” content=“email@example.com”>
  11.  
  12. <!– 最好使用 <link rel=”author”> 或 humans.txt 文件 –>
  13. <meta name=“author” content=“name, email@example.com”>
  14. <meta name=“designer” content=“”>
  15. <meta name=“owner” content=“”>
  16.  
  17. <!– 告诉搜索机器人一段时间后重新访问该网页。这不支持,因为大多数搜索引擎使用随机时间间隔来重新抓取网页 –>
  18. <meta name=“revisit-after” content=“7 days”>
  19.  
  20. <!– 在一段时间后将用户重定向到新的 URL –>
  21. <!– W3C 建议不要使用该标签。Google 建议使用服务器端的 301 重定向。–>
  22. <meta http-equiv=“refresh” content=“300; url=https://example.com/”>
  23.  
  24. <!– 描述网站的主题 –>
  25. <meta name=“topic” content=“”>
  26.  
  27. <!– 公司概要或网站目的 –>
  28. <meta name=“summary” content=“”>
  29.  
  30. <!– 一个已废弃的标签,和关键词 meta 标签的作用相同 –>
  31. <meta name=“classification” content=“business”>
  32.  
  33. <!– 是否是相同的 URL,年代久远且不支持 –>
  34. <meta name=“identifier-URL” content=“https://example.com/”>
  35.  
  36. <!– 和关键词标签类似的功能 –>
  37. <meta name=“category” content=“”>
  38.  
  39. <!– 确保你的网站在所有国家和语言中都能显示 –>
  40. <meta name=“coverage” content=“Worldwide”>
  41.  
  42. <!– 和 coverage 标签相同 –>
  43. <meta name=“distribution” content=“Global”>
  44.  
  45. <!– 控制在互联网上哪些用户可以访问 –>
  46. <meta http-equiv=“Pics-label” content=“value”>
  47.  
  48. <!– 缓存控制 –>
  49. <!– 最好在服务器端配置缓存控制 –>
  50. <meta http-equiv=“Expires” content=“0”>
  51. <meta http-equiv=“Pragma” content=“no-cache”>
  52. <meta http-equiv=“Cache-Control” content=“no-cache”>

link 标签

说到 link 标签,估计大家的第一反应和我一样,就是引入外部CSS样式文件的,不错,这是 link 标签最最常用的功能。不过它还有很多别的用处,比如这是浏览器 favicon 图标,touch图标等等。

html 代码:
  1. <!– 有助于防止出现内容重复的问题 –>
  2. <link rel=“canonical” href=“https://example.com/2010/06/9-things-to-do-before-entering-social-media.html”>
  3.  
  4. <!– 之前用于包含 icon 链接,但已被废弃并不再使用 –>
  5. <link rel=“shortlink” href=“https://example.com/?p=42”>
  6.  
  7. <!– 链接到当前文档的一个 AMP HTML 版本 –>
  8. <link rel=“amphtml” href=“https://example.com/path/to/amp-version.html”>
  9.  
  10. <!– 表明一个 CSS 样式表 –>
  11. <link rel=“stylesheet” href=“https://example.com/styles.css”>
  12.  
  13. <!– 链接到一个指定 Web 应用程序“安装”证书的 JSON 文件 –>
  14. <link rel=“manifest” href=“manifest.json”>
  15.  
  16. <!– 链接到文档的作者 –>
  17. <link rel=“author” href=“humans.txt”>
  18.  
  19. <!– 指向一个适用于链接内容的版权申明 –>
  20. <link rel=“copyright” href=“copyright.html”>
  21.  
  22. <!– 给出可能的你的另一种语言的文档位置参考 –>
  23. <link rel=“alternate” href=“https://es.example.com/” hreflang=“es”>
  24.  
  25. <!– 提供了关于作者或其他人的信息 –>
  26. <link rel=“me” href=“https://google.com/profiles/thenextweb” type=“text/html”>
  27. <link rel=“me” href=“mailto:name@example.com”>
  28. <link rel=“me” href=“sms:+15035550125”>
  29.  
  30. <!– 链接到一个文档,包含当前文档的一个归档链接 –>
  31. <link rel=“archives” href=“https://example.com/2003/05/” title=“May 2003”>
  32.  
  33. <!– 链接到层次结构中的顶级资源 –>
  34. <link rel=“index” href=“https://example.com/” title=“DeWitt Clinton”>
  35.  
  36. <!– 给出该文档的起点 –>
  37. <link rel=“start” href=“https://example.com/photos/pattern_recognition_1_about/” title=“Pattern Recognition 1”>
  38.  
  39. <!– 引导当前文档的前述资源序列 –>
  40. <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.”>
  41.  
  42. <!– 给出一个自我参考 – 当文档有多个可能的参考时非常有用 –>
  43. <link rel=“self” type=“application/atom+xml” href=“https://example.com/atomFeed.php?page=3”>
  44.  
  45. <!– 分别是在一系列文件中的第一个、下一个、上一个和最后一个 –>
  46. <link rel=“first” href=“https://example.com/atomFeed.php”>
  47. <link rel=“next” href=“https://example.com/atomFeed.php?page=4”>
  48. <link rel=“previous” href=“https://example.com/atomFeed.php?page=2”>
  49. <link rel=“last” href=“https://example.com/atomFeed.php?page=147”>
  50.  
  51. <!– 当使用第三方服务来维护 blog 时使用 –>
  52. <link rel=“EditURI” href=“https://example.com/xmlrpc.php?rsd” type=“application/rsd+xml” title=“RSD”>
  53.  
  54. <!– 当另一个 WordPress 博客链接到你的 WordPress 博客或文章时形成一个自动化的评论 –>
  55. <link rel=“pingback” href=“https://example.com/xmlrpc.php”>
  56.  
  57. <!– 当你在自己的页面上链接到一个 url 时通知它 –>
  58. <link rel=“webmention” href=“https://example.com/webmention”>
  59.  
  60. <!– 加载一个外部的 HTML 文件到当前 HTML 文件中 –>
  61. <link rel=“import” href=“component.html”>
  62.  
  63. <!– 打开搜索 –>
  64. <link rel=“search” href=“/open-search.xml” type=“application/opensearchdescription+xml” title=“Search Title”>
  65.  
  66. <!– Feeds –>
  67. <link rel=“alternate” href=“https://feeds.feedburner.com/example” type=“application/rss+xml” title=“RSS”>
  68. <link rel=“alternate” href=“https://example.com/feed.atom” type=“application/atom+xml” title=“Atom 0.3”>
  69.  
  70. <!– 预取,预载,预浏览 –>
  71. <link rel=“dns-prefetch” href=“//example.com/”>
  72. <link rel=“preconnect” href=“https://www.example.com/”>
  73. <link rel=“prefetch” href=“https://www.example.com/”>
  74. <link rel=“prerender” href=“https://example.com/”>
  75. <link rel=“preload” href=“image.png” as=“image”>
  76. <!– 更多信息:https://css-tricks.com/prefetching-preloading-prebrowsing/ –>

具体说明查看:https://css-tricks.com/prefetching-preloading-prebrowsing/

rss订阅

html 代码:
  1. <link rel=“alternate” type=“application/rss+xml” title=“RSS” href=“/rss.xml” /> <!– 添加 RSS 订阅 –>

不推荐的link标签

以下是不推荐使用的链接关系:

html 代码:
  1. <link rel=“shortcut icon” href=“path/to/favicon.ico”>
  2.  
  3. <!– 没有用的, 专有的和错误的, 详见 https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/Y_2eFRh9BOs/gULYapoRBwAJ –>
  4. <link rel=“subresource” href=“styles.css”>

具体说明查看:https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/Y_2eFRh9BOs/gULYapoRBwAJ

favicon 图标

IE 11, Chrome, Firefox, Safari, Opera支持<link>形式设置:

html 代码:
  1. <link rel=“icon” href=“path/to/favicon-16.png” sizes=“16×16” type=“image/png”>
  2. <link rel=“icon” href=“path/to/favicon-32.png” sizes=“32×32” type=“image/png”>
  3. <link rel=“icon” href=“path/to/favicon-48.png” sizes=“48×48” type=“image/png”>
  4. <link rel=“icon” href=“path/to/favicon-62.png” sizes=“62×62” type=“image/png”>
  5. <link rel=“icon” href=“path/to/favicon-192.png” sizes=“192×192” type=“image/png”>

注意:对于IE 10及以下版本不支持<link>形式设置,只通过将命名为favicon.ico的文件放置在网站根目录中实现。

比较详细的 favicon 介绍可参考:

  • 所有关于网站图标(和触摸图标)
  • favicon 对照表

浏览器及平台详细说明

QQ 浏览器(X5 内核)

QQ 浏览器(X5 内核)同样适用于微信,QQ等第三方应用页面开发。

html 代码:
  1. <!– 设置锁定横屏、竖屏显示模式,portrait(横屏),landscape(竖屏)–>
  2. <meta name=“x5-orientation” content=“portrait|landscape”>
  3. <!– 设置全屏显示页面 –>
  4. <meta name=“x5-fullscreen” content=“true”>
  5. <!– 开启页面以应用模式显示(全屏显示等) –>
  6. <meta name=“x5-page-mode” content=“app”>

360浏览器

设置 360 浏览器渲染模式:webkit 为极速内核,ie-comp 为 IE 兼容内核,ie-stand 为 IE 标准内核。

html 代码:
  1. <meta name=“renderer” content=“webkit|ie-comp|ie-stand”>

详情文档链接:浏览器内核控制Meta标签说明文档
360 浏览器就会在读取到这个标签后,立即切换对应的极速核。 另外为了保险起见再加入

html 代码:
  1. <meta http-equiv=“X-UA-Compatible” content=“IE=Edge,chrome=1”>

这样写可以达到的效果是如果安装了 Google Chrome Frame,则使用 GCF 来渲染页面,如果没有安装 GCF,则使用最高版本的 IE 内核进行渲染。

UC 浏览器

设置屏幕方向

portrait 为横屏,landscape 为竖屏。

html 代码:
  1. <meta name=“screen-orientation” content=“portrait|landscape”>

设置全屏

html 代码:
  1. <meta name=“full-screen” content=“yes”>

设置适应屏幕排版(缩放是否显示滚动条)

UC 浏览器在标准排版效果实现的基础上,提供适应屏幕的排版方式,当设置为 uc-fitscreen=yes,页面进行缩放操作时,仅放大图片和文字等元素,但不放大屏幕宽度,保持不出现水平(横向)滚动条。

html 代码:
  1. <meta name=“viewport” content=“uc-fitscreen=no|yes”>

排版模式

UC 浏览器提供两种排版模式,分别是适屏模式(fitscreen)及标准模式(standard),其中适屏模式简化了一些页面的处理,使得页面内容更适合进行页面阅读、节省流量及响应更快,而标准模式则能按照标准规范对页面进行排版及渲染。

html 代码:
  1. <meta name=“layoutmode” content=“fitscreen|standard”>

夜间模式

可以帮助用户在低亮度或黑暗情况下更舒适的进行页面浏览。由于基于网页的应用愈加复杂,由浏览器实现的单一夜间模式不一定能够适应所有情况(例如游戏应用),因此 UC 浏览器允许网页设计者对其设计的页面禁用浏览器的夜间模式,自行设计更适合用户使用的夜间模式。

注意:页面内的 frame/iframe 中的夜间模式的 meta 不生效。

html 代码:
  1. <meta name=“nightmode” content=“enable|disable”>

整页图片强制显示

为了节省流量及加快速度,UC 为用户提供了无图模式,在实际使用中存在页面中的图片是不可缺少的,例如验证码,地图等。通过强制图片显示的功能可以保证图片显示不受用户的设置影响。

**注意:整页图片强制显示仅对当前页面生效,对页面内的 frame/iframe 不生效,也不影响前进后退的页面

html 代码:
  1. <meta name=“imagemode” content=“force”>

开启应用模式

html 代码:
  1. <meta name=“browsermode” content=“application”>

应用模式是为方便 Web 应用及游戏开发者设置的综合开关,通过meta标签进行指示打开,当进入应用模式时,浏览器将自动调整以下参数:

参数 状态 说明
全屏 生效 可通过 meta 或 JS API 调用退出全屏
长按菜单 失效 可通过 JS API 调用重新生效
浏览器默认手势 失效 可通过 JS API 调用重新生效
排版模式 标准模式 可通过 meta 或 JS API 调用设置其他排版模式
强制图片显示 生效 /
夜间模式 失效 可通过 meta 或 JS API 调用启用夜间模式

缩放字体

例如:禁用的 UC 浏览器的字体缩放功能

html 代码:
  1. <meta name=“wap-font-scale” content=“no”>

具体UC 浏览器文档链接:UC 浏览器文档

Apple iOS原生浏览器

添加智能 App 广告条

告诉浏览器这个网站对应的app,并在页面上显示下载banner,需要注意的是Smart App Banners标签不能用在frame框架内部,否则不起作用。

其中app-id(必须), affiliate-data (可选), app-argument (可选)

html 代码:
  1. <meta name=“apple-itunes-app” content=“app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT”>

例如Digg的写法:

html 代码:
  1. <meta name=“apple-itunes-app” content=“app-id=362872995, affiliate-data=bevbOqLt02I, app-argument=digg://”>

忽略数字自动识别为电话号码

html 代码:
  1. <meta name=“format-detection” content=“telephone=no”>

启用 WebApp 全屏模式

html 代码:
  1. <meta name=“apple-mobile-web-app-capable” content=“yes”>
添加到主屏后设置状态栏的背景颜色
html 代码:
  1. <meta name=“apple-mobile-web-app-status-bar-style” content=“black”>

只有在 “apple-mobile-web-app-capable” content=”yes” 时生效。

  • 如果设置为 default 或 black ,网页内容从状态栏底部开始。
  • 如果设置为 black-translucent ,网页内容充满整个屏幕,顶部会被状态栏遮挡。
添加到主屏后的标题(iOS 6 新增)
html 代码:
  1. <meta name=“apple-mobile-web-app-title” content=“App Title”>

iOS 图标

图片自动处理成圆角和高光等效果。

html 代码:
  1. <link rel=“apple-touch-icon” href=“path/to/apple-touch-icon.png”>

禁止系统自动添加效果,直接显示设计原图。

html 代码:
  1. <link rel=“apple-touch-icon-precomposed” href=“path/to/apple-touch-icon-precomposed.png”>

iOS 8+ 不再支持 precomposed, 只有 apple-touch-icon 是必须的
在大多数情况下,在head中一个180×180px的图标就足够了。如果您想要由设备确定的唯一图标,请使用不同大小的图标。

html 代码:
  1. <link rel=“apple-touch-icon” sizes=“57×57” href=“path/to/icon@57.png”>
  2. <link rel=“apple-touch-icon” sizes=“72×72” href=“path/to/icon@72.png”>
  3. <link rel=“apple-touch-icon” sizes=“114×114” href=“path/to/icon@114.png”>
  4. <link rel=“apple-touch-icon” sizes=“144×144” href=“path/to/icon@144.png”>

启动画面 ( 不赞成使用 )

iPad 的启动画面是不包括状态栏区域的,iPhone 和 iPod touch 的启动画面是包含状态栏区域的

html 代码:
  1. <link rel=“apple-touch-startup-image” href=“path/to/startup.png”>

具体描述设置请查看http://www.css88.com/archives/5480中相应的说明。

iOS 应用深度链接

html 代码:
  1. <meta name=“apple-itunes-app” content=“app-id=APP-ID, app-argument=http/url-sample.com”>
  2. <link rel=“alternate” href=“ios-app://APP-ID/http/url-sample.com”>

Google Android原生浏览器

标签页选项卡颜色

Android Lollipop 中的 Chrome 39 增加 theme-color meta 标签,用来控制选项卡颜色。

http://updates.html5rocks.com/2014/11/Support-for-theme-color-in-Chrome-39-for-Android

68747470733a2f2f646576656c6f706572732e676f6f676c652e636f6d2f7765622f757064617465732f696d616765732f323031342f31312f7468656d652d636f6c6f722d73732e706e67

html 代码:
  1. <meta name=“theme-color” content=“#db5945”>

添加到主屏

html 代码:
  1. <!– 添加到主屏 –>
  2. <meta name=“mobile-web-app-capable” content=“yes”>

详细链接: https://developer.chrome.com/multidevice/android/installtohomescreen

安卓应用深度链接(网页上唤起应用)

html 代码:
  1. <!– Android app deep linking –>
  2. <meta name=“google-play-app” content=“app-id=package-name”>
  3. <link rel=“alternate” href=“android-app://package-name/http/url-sample.com”>

注:貌似没测试成功,如果你知道如何正确设置,欢迎留言斧正。

Apple Safari 浏览器

Safari 10开始支持固定书签页的SVG favicons了,你可以这样使用:

html 代码:
  1. <!– Pinned Site –>
  2. <link rel=“mask-icon” href=“path/to/icon.svg” color=“red”>

类似的效果
safari-pinned-tabs
扩展阅读:https://yoast.com/dev-blog/safari-pinned-tab-icon-mask-icon/

Google Chrome浏览器

关闭chrome浏览器下翻译插件

有些时候感觉chrome浏览器下翻译插件很烦人,可以通过下面的代码禁用它。

html 代码:
  1. <meta name=“google” value=“notranslate” />

BB5FACB6-7DFE-41D6-AB27-9C2E91130061

chrome浏览器插件安装

有时候,你需要在你的页面上点击某个安卓,直接安卓你的chrome浏览器插件,而不是链接到Chrome webstore 的详细地址再安装,那么你可以使用:

html 代码:
  1. <link rel=“chrome-webstore-item” href=“https://chrome.google.com/webstore/detail/APP_ID”>

具体使用,请查看:Using Inline Installation

Google Chrome Mobile (只针对 Android)

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

html 代码:
  1. <!– 链接到一个 manifest 并定义 manifest 的元数据。–>
  2. <!– manifest.json 中的例子也可以通过以下链接找到。–>
  3. <link rel=“manifest” href=“manifest.json”>
  4.  
  5. <!– 定义你的网页为 Web 应用 –>
  6. <meta name=“mobile-web-app-capable” content=“yes”>
  7.  
  8. <!– 第一个是官方推荐格式。–>
  9. <link rel=“icon” sizes=“192×192” href=“nice-highres.png”>
  10. <link rel=“icon” sizes=“128×128” href=“niceicon.png”>
  11. <!– 所有带 apple 前缀的格式已废弃,所以不要使用它们。–>
  12. <link rel=“apple-touch-icon” sizes=“128×128” href=“niceicon.png”>
  13. <link rel=“apple-touch-icon-precomposed” sizes=“128×128” href=“niceicon.png”>

Internet Explorer浏览器

模式设置

js 代码:
  1. //IE8以下以IE7标准模式呈现网页,而IE9则以IE9的标准模式呈现网页:
  2. <meta httpequiv=“X-UA-Compatible” content=“IE=EmulateIE7; IE=EmulateIE9”>
  3. //如果安装了GCF,则使用GCF来渲染页面(”chrome=1″),
  4. //如果没有安装GCF,则使用最高版本的IE内核进行渲染(”IE=edge”)
  5. <meta httpequiv=“x-ua-compatible” content=“ie=edge”>

GCF(Google Chrome Frame )相关链接:https://www.chromium.org/developers/how-tos/chrome-frame-getting-started

X-UA-Compatible相关链接:https://blogs.msdn.microsoft.com/ie/2010/06/16/ies-compatibility-features-for-site-developers/

win8,win10下的一些设置

html 代码:
  1. <meta http-equiv=“cleartype” content=“on”>
  2. <meta name=“skype_toolbar” content=“skype_toolbar_parser_compatible”>
  3.  
  4. <!–
  5. Disable link highlighting on IE 10 on Windows Phone
  6. 具体说明查看:https://blogs.windows.com/buildingapps/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10/–>
  7. <meta name=“msapplication-tap-highlight” content=“no”>
  8.  
  9. <!–
  10. Pinned sites
  11. 具体说明查看:https://msdn.microsoft.com/en-us/library/dn255024(v=vs.85).aspx–>
  12. <meta name=“application-name” content=“Contoso Pinned Site Caption”>
  13. <meta name=“msapplication-tooltip” content=“Example Tooltip Text”>
  14. <meta name=“msapplication-starturl” content=“/”>
  15.  
  16. <meta name=“msapplication-config” content=“http://example.com/browserconfig.xml”>
  17.  
  18. <meta name=“msapplication-allowDomainApiCalls” content=“true”>
  19. <meta name=“msapplication-allowDomainMetaTags” content=“true”>
  20. <meta name=“msapplication-badge” content=“frequency=30; polling-uri=http://example.com/id45453245/polling.xml”>
  21. <meta name=“msapplication-navbutton-color” content=“#FF3300”>
  22. <meta name=“msapplication-notification” content=“frequency=60;polling-uri=http://example.com/livetile”>
  23. <meta name=“msapplication-square150x150logo” content=“path/to/logo.png”>
  24. <meta name=“msapplication-square310x310logo” content=“path/to/largelogo.png”>
  25. <meta name=“msapplication-square70x70logo” content=“path/to/tinylogo.png”>
  26. <meta name=“msapplication-wide310x150logo” content=“path/to/widelogo.png”>
  27. <meta name=“msapplication-task” content=“name=Check Order Status;action-uri=./orderStatus.aspx?src=IE9;icon-uri=./favicon.ico”>
  28. <meta name=“msapplication-task-separator” content=“1”>
  29. //Windows 8 磁贴颜色
  30. <meta name=“msapplication-TileColor” content=“#FF3300”>
  31. //Windows 8 磁贴图标
  32. <meta name=“msapplication-TileImage” content=“path/to/tileimage.jpg”>
  33. <meta name=“msapplication-window” content=“width=1024;height=768”>

APP 链接

html 代码:
  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 Fallback –>
  10. <meta property=“al:web:url” content=“http://applinks.org/documentation”>
  11. <!– More info: http://applinks.org/documentation/ –>

具体请查看:App Links Docs

未经允许不得转载:Bcoder资源网 » HTML5 head 头标签使用大全

相关推荐

更多优质资源关注微信公众号: bcoder

bcoder
赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册