最小推荐
以下是基本的简约网站的基本标签:
<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的前面; 任何其他头部内容必须放在这些标签之后 -->
<title>Page Title</title>
元素
<head>内有效的元素包括: meta, link, title, style, script, noscript以及base。
<!-- 字符集Charset -->
<meta charset="utf-8">
<!-- 标题 -->
<title>Page Title</title>
<!-- document里所有相对URL的base URL -->
<base href="http://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的前面; 任何其他头部内容必须放在这些标签之后 -->
<!-- Allows control over where resources are loaded from -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<!-- 尽早放到文件里 -->
<!-- 只对标签下的内容适用 -->
<!-- Web应用的名称(仅当该网站用作app时才应使用) -->
<meta name="application-name" content="Application Name">
<!-- 页面简短说明(限150个字符) -->
<!-- 在*某些*情况下,此描述用作搜索结果中显示的一部分。 -->
<meta name="description" content="A description of the page">
<!-- 控制搜索引擎抓取和索引的行为 -->
<meta name="robots" content="index,follow"><!--所有搜索引擎 -->
<meta name="googlebot" content="index,follow"><!-- 指定Google-->
<!-- 告诉Google不要显示站内搜索框 -->
<meta name="google" content="nositelinkssearchbox">
<!-- 告诉Google不要为此页面提供翻译 -->
<meta name="google" content="notranslate">
<!-- 验证所有权 -->
<meta name="google-site-verification" content="verification_token"><!-- Google Search Console -->
<meta name="yandex-verification" content="verification_token"><!-- Yandex Webmasters -->
<meta name="msvalidate.01" content="verification_token"><!-- Bing Webmaster Center -->
<meta name="alexaVerifyID" content="verification_token"><!-- Alexa Console -->
<meta name="p:domain_verify" content="code_from_pinterest"><!-- Pinterest Console-->
<meta name="norton-safeweb-site-verification" content="norton_code"><!-- Norton Safe Web -->
<!-- 命名用于构建网站的软件(例如 - WordPress,Dreamweaver) -->
<meta name="generator" content="软件名">
<!-- 网站主题的简短描述 -->
<meta name="subject" content="你的网站主题">
<!-- 根据网站内容给出一般的年龄评估 -->
<meta name="rating" content="General">
<!-- Allows control over how referrer information is passed -->
<meta name="referrer" content="no-referrer">
<!-- 禁用自动检测和格式化可能的电话号码 -->
<meta name="format-detection" content="telephone=no">
<!-- 设置为“off”完全退出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">
<!-- 地理位置Geo标签 -->
<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)
<!-- Points to a CSS stylesheet -->
<link rel="stylesheet" href="http://example.com/styles.css">
<!-- Helps prevent duplicate content issues -->
<link rel="canonical" href="http://example.com/2010/06/9-things-to-do-before-entering-social-media.html">
<!-- Used to be included before the icon link, but is deprecated and no longer is used -->
<link rel="shortlink" href="http://example.com/?p=42">
<!-- Links to an AMP HTML version of the current document -->
<link rel="amphtml" href="http://example.com/path/to/amp-version.html">
<!-- Links to a JSON file that specifies "installation" credentials for web applications -->
<link rel="manifest" href="manifest.json">
<!-- Links to the author of the document -->
<link rel="author" href="humans.txt">
<!-- Refers to a copyright statement that applies to the links context -->
<link rel="license" href="copyright.html">
<!-- Gives a reference to a location in your document that may be in another language -->
<link rel="alternate" href="https://es.example.com/" hreflang="es">
<!-- Gives information about an author or another person -->
<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">
<!-- Links to a document that describes a collection of records, documents, or other materials of historical interest. -->
<link rel="archives" href="http://example.com/archives/">
<!-- Links to top level resource in an hierarchical structure -->
<link rel="index" href="http://example.com/">
<!-- Gives a self reference - useful when the document has multiple possible references -->
<link rel="self" type="application/atom+xml" href="http://example.com/atomFeed.php?page=3">
<!-- The first, next, previous, and last documents in a series of documents, respectively -->
<link rel="first" href="http://example.com/atomFeed.php">
<link rel="next" href="http://example.com/atomFeed.php?page=4">
<link rel="prev" href="http://example.com/atomFeed.php?page=2">
<link rel="last" href="http://example.com/atomFeed.php?page=147">
<!-- Used when using a 3rd party service to maintain a blog -->
<link rel="EditURI" href="http://example.com/xmlrpc.php?rsd" type="application/rsd+xml" title="RSD">
<!-- Forms an automated comment when another WordPress blog links to your WordPress blog or post -->
<link rel="pingback" href="http://example.com/xmlrpc.php">
<!-- Notifies a url when you link to it on your site -->
<link rel="webmention" href="http://example.com/webmention">
<!-- Enables posting to your own domain using a Micropub client -->
<link rel="micropub" href="http://example.com/micropub">
<!-- Loads in an external HTML file into the current HTML file -->
<link rel="import" href="/path/to/component.html">
<!-- Open Search -->
<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="http://example.com/feed.atom" type="application/atom+xml" title="Atom 0.3">
<!-- Prefetching, preloading, prebrowsing -->
<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="http://example.com/">
<link rel="preload" href="image.png" as="image">
<!-- More info: https://css-tricks.com/prefetching-preloading-prebrowsing/ -->
网站图标(Favicons)
<!-- For IE 10 and below -->
<!-- Place favicon.ico in the root directory - no tag necessary -->
<!-- For IE 11, Chrome, Firefox, Safari, Opera -->
<link rel="icon" type="image/png" sizes="16x16" href="/path/to/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/path/to/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/path/to/favicon-96x96.png">
社交(Social)
Facebook Open Graph
<meta property="fb:app_id" content="123456789">
<meta property="og:url" content="http://example.com/page.html">
<meta property="og:type" content="website">
<meta property="og:title" content="Content Title">
<meta property="og:image" content="http://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="">
Twitter Card
<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="http://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="http://example.com/image.jpg">
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="http://example.com/image.jpg">
根据Pinterest的帮助中心,它允许你阻止人们在你的网站上存储东西。 description是可选的。
<meta name="pinterest" content="nopin" description="对不起,你不能保存在本网站">
Facebook即时文章
<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">
Instant Articles: 格式参考
OEmbed
<link rel="alternate" type="application/json+oembed"
href="http://example.com/services/oembed?url=http%3A%2F%2Fexample.com%2Ffoo%2F&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&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">
<!-- 触摸图标 -->
<!-- 多数情况下,180×180px的触摸图标在头部就足够了 -->
<link rel="apple-touch-icon" href="/path/to/apple-touch-icon.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">
<!-- 更多信息: 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" content="notranslate">
Google Chrome手机版(仅限Android)
从Chrome 31开始,可以将web应用设置为“app mode”,类似于Safari。
<!-- 链接到manifest文件,并定义它元数据。 -->
<!-- 如下面例子里的manifest.json文件 -->
<link rel="manifest" href="manifest.json">
<!-- 定义web页面为web app -->
<meta name="mobile-web-app-capable" content="yes">
<!-- 主屏图标 -->
<link rel="icon" sizes="192x192" href="/path/to/highres-icon.png">
微软的Internet Explorer
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">
<!-- IE10:点击后禁用链接突出显示(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="Sample Title">
<meta name="msapplication-tooltip" content="A description of what this site does.">
<meta name="msapplication-starturl" content="http://example.com/index.html?pinned=true">
<meta name="msapplication-navbutton-color" content="#FF3300">
<meta name="msapplication-window" content="width=800;height=600">
<meta name="msapplication-task" content="name=Task 1;action-uri=http://host/Page1.html;icon-uri=http://host/icon1.ico">
<meta name="msapplication-task" content="name=Task 2;action-uri=http://microsoft.com/Page2.html;icon-uri=http://host/icon2.ico">
<meta name="msapplication-badge" value="frequency=NUMBER_IN_MINUTES;polling-uri=http://example.com/path/to/file.xml">
<meta name="msapplication-TileColor" content="#FF3300">
<meta name="msapplication-TileImage" content="/path/to/tileimage.jpg">
<meta name="msapplication-config" content="http://example.com/browserconfig.xml">
<meta name="msapplication-notification" content="frequency=60;polling-uri=http://example.com/livetile;polling-uri2=http://example.com/livetile2">
<meta name="msapplication-task-separator" content="1">
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 回退-->
<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">
注意
性能
当启用 GZIP 时,移动 href 属性到该元素的开头以提高压缩,因为 href 属性被用于 a、base 和 link 标签。
示例:
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">
其他资源
HTML5 样板文档:扩展和定制
相关项目
-
Atom HTML Head 片段 - Atom
HEAD
片段包 -
Sublime Text HTML Head 片段 - Sublime Text
HEAD
片段包 -
head-it -
HEAD
片段的 CLI 接口 -
vue-head - 在 Vue.js 中操作
HEAD
标签的 meta 信息