HTML 5 <meta> 标签

定义和用法

<meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词。

<meta> 标签位于文档的头部,不包含任何内容。<meta> 标签的属性定义了与文档相关联的名称/值对。

HTML 4.01 与 HTML 5 之间的差异

在 HTML 5 中,不再支持 scheme 属性。

在 HTML 5 中,有一个新的 charset 属性,它使字符集的定义更加容易。

在 HTML 4.01 中,不得不这么写:

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

在 HTML 5 中,这样就够了:

<meta charset="ISO-8859-1">

提示和注释

提示:请使用 CSS 来定义列表的类型。

例子

定义针对搜索引擎的关键词:

<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript" />

定义对页面的描述:

<meta name="description" content="免费的 web 技术教程。" />

定义页面的最新版本:

<meta name="revised" content="David, 2008/8/8/" />

每 5 秒刷新一次页面:

<meta http-equiv="refresh" content="5" />

属性

属性 描述 4 5
charset character encoding 定义文档的字符编码。   5
content some_text 定义与 http-equiv 或 name 属性相关的元信息。 4 5
http-equiv
  • content-type
  • expires
  • refresh
  • set-cookie
把 content 属性关联到 HTTP 头部。 4 5
name
  • author
  • description
  • keywords
  • generator
  • revised
  • others
把 content 属性关联到一个名称。 4 5
scheme some_text 定义用于翻译 content 属性值的格式。不支持。 4  

标准属性

class, contenteditable, contextmenu, dir, draggable, id, irrelevant, 
lang, ref, registrationmark, tabindex, template, title

事件属性

onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu, 
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover, 
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup, 
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout, 
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload