HTML <meta>标签
HTML <meta>标签
HTML <meta>标签用于表示有关HTML文档的元数据。它指定页面描述,关键字,版权,语言,文档作者等。
元数据不会显示在网页上,但是搜索引擎,浏览器和其他扫描网页内容的Web服务会使用它。网站或网页以了解该网页。
借助meta标签,您可以尝试并预览网页在浏览器中的呈现方式。
<meta>标签位于<head>标签内,并且可以在文档中使用多次。
语法:
以下是有关HTML <meta>标签的一些规范
显示 |
无 |
开始标签/结束标签 |
空标签(仅开始标签) |
用法 |
文档结构 |
以下是元标签的一些特定语法,这些语法显示了元标签的不同用法。
1. <meta charset="utf-8">
它定义字符编码。charset的值为"utf-8",表示它将支持显示任何语言。
2. <meta name="keywords" content="HTML, CSS, JavaScript, Tutorials">
它指定搜索引擎使用的关键字列表。
3. <meta name="description" content="Free Online tutorials">
它定义了网站描述,可用于提供搜索引擎执行的相关搜索。
4. <meta name="author" content="thisauthor">
它指定页面的作者。由内容管理系统自动提取作者信息很有用。
5. <meta name="refresh" content="50">
它指定向浏览器提供指令,以每50秒(或任何给定时间)自动刷新内容。
6. <meta http-equiv="refresh" content="5; url=https://www.lidihuo.com/html-tags-list">
在上面的示例中,我们设置了带有内容的URL,因此它将在提供的时间后自动重定向到给定的页面。
7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
它指定视口以控制页面尺寸和缩放比例,以便我们的网站在所有设备上均显示良好。如果存在此标签,则表明此页面受移动设备支持。
示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="HTML, CSS, JavaScript, Tutorials">
<meta name="description" content="Free Online tutorials">
<meta name="author" content="thisauthor">
<meta http-equiv="refresh" content="5; url=https://www.lidihuo.com/html-tags-list">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2>Example of Meta tag</h2>
<p>This example shows the use of meta tag within an HTML document</p>
</body>
</html>
属性:
标签特定的属性:
= HTML5的新功能
支持 |
属性 |
值 |
说明 |
字符集 |
character_set |
它指定HTML页面的字符编码。 |
content |
text |
根据上下文,它包含HTML文档中属性"名称"和" http等效"的值。 |
http-equiv |
Content-type default-style refresh |
它指定Web服务器给出的有关如何服务网页的信息。 |
name |
application-name author description generator keywords |
它指定文档级元数据的名称。 |
scheme |
format/URL |
它指定描述元数据的方案。(HTML5不支持) |
全局属性:
<meta>标签支持HTML中的全局属性
事件属性:
<meta>标签支持HTML中的事件属性。
支持浏览器