元数据(metadata)提供有关页面的元信息。元数据不会显示在页面上,可是对于机器是可读的。
meta 元素常被用于规定页面的描述、关键词、文档的做者、最后修改时间以及其余元数据。标签始终位于 head 元素中。
元数据老是以 键/值 对的形式被成对传递的。
<meta>
标签的属性定义了与文档相关联的 键/值 对。html
HTML5中新添加的,用于定义字符集。尽可能写在第一行,否则可能会产生乱码。web
<meta charset="UTF-8">
当 meta 有 http-equiv 或 name 属性时,必定要有 content 属性对其进行说明。chrome
http-equiv 属性是添加http头部内容的。该属性为 键/值 对提供了键名。并指示服务器在发送实际的文档以前先在要传送给浏览器的 MIME 文档头部包含该 键/值 对。windows
content-type:设定网页类型,设置字符集,适用于旧的HTML版本,推荐使用charset属性。浏览器
<meta http-equiv="content-Type" content="text/html;charset=utf-8">
X-UA-Compatible:浏览器采起何种版本渲染当前页面,通常都设置为最新模式。缓存
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
refresh:重定向页面,content 中的数字表示秒数,若是没有url,表示刷新页面;有url,表示5秒后重定向至新的网址。服务器
<meta http-equiv="refresh" content="5;url=https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/meta">
cache-controlapp
指定请求和响应遵循的缓存机制工具
<meta http-equiv="cache-control" content="no-cache">
content 参数:布局
禁止百度自动转码:禁止当前页面在移动端浏览时,被百度自动转码,不过不保证100%禁止。
<meta http-equiv="cache-control" content="no-siteapp"> <meta http-equiv="cache-control" content="no-transform">
pragma:cache模式,禁止缓存,没法脱机浏览。
<meta http-equiv="pragma" content="no-cache">
expires:网页到期时间,过时后必须到服务器上从新传输。必须使用 GMT 时间格式,或直接设为0。
<meta http-equiv="expires" content="0">
name 属性是供浏览器进行解析。没有指定具体的值,一般状况下,能够自由使用对本身和源文档的读者来讲富有意义的名称。前提是浏览器可以解析写进去的name属性才能够,否则就是没有意义的。
renderer:这个meta标签的意思就是告诉浏览器,用webkit内核进行解析,固然前提是浏览器有webkit内核才能够。这个 renderer 是在360浏览器里说明的。360浏览器meta文档说明
<meta name="renderer" content="webkit|ie-comp|ie-stand">
定义网页搜索引擎爬虫的索引方式,告诉爬虫哪些页面须要索引,哪些不须要索引。
<meta name="robots" content="index,follow">
content 参数:
<!-- keywords 页面关键字(由于被滥用,SEO 已经取消了关键字搜索了) --> <meta name="keywords" content="word1,word2,word3"> <!-- description 页面内容描述 --> <meta name="description" content="ye mian miao shu"> <!-- author 定义网页做者 --> <meta name="author" content="Dora">
viewport 主要是影响移动端页面布局的
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0">
content 参数:
<!-- 忽略页面中的数字识别为电话,忽略email识别 --> <meta name="format-detection" content="telphone=no, email=no"> <!-- windows phone 点击无高光 --> <meta name="msapplication-tap-highlight" content="no">
<!-- 优先使用最新的 ie 版本,避免使用兼容模式 --> <meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- 优先使用最新的 Chrome 版本 --> <meta http-equiv="x-ua-compatible" content="chrome=1"> <!-- 禁止自动翻译 --> <meta name="google" value="notranslate">
<!-- 选择360浏览器的解析内核,启用 webkit 极速模式 --> <meta name="rederer" content="webkit">
<!-- 将屏幕锁定在特定的方向 --> <meta name="screen-orientation" content="landscape|portrait"> <!-- 强制全屏 --> <meta name="full-screen" content="yes"> <!-- 强制图片显示,即便是“text mode" --> <meta name="imagemode" content="force"> <!-- 应用模式显示,默认全屏,禁止长按菜单,禁止手势,标准排版,强制图片显示。 --> <meta name="browsermode" content="application"> <!-- 禁止夜间模式显示 --> <meta name="nightmode" content="disable"> <!-- 使用适屏模式显示 --> <meta name="layoutmode" content="fitscreen"> <!-- 当页面有太多文字时禁止缩放 --> <meta name="wap-font-scale" content="no">
<!-- 将屏幕锁定在特定方向 --> <meta name="x5-orientation" content="landscape|portrait"> <!-- 强制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- 页面以应用模式显示 --> <meta name="x5-page-mode" content="app">
<!-- Add to Home Screen添加到主屏 --> <!-- 是否启用 WebApp 全屏模式,删除苹果默认的工具栏和菜单栏 --> <meta name="apple-mobile-web-app-capable" content="yes"> <!-- 设置状态栏的背景颜色,只有在 “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">