HTML 5 <meta> 標(biāo)簽
定義和用法
<meta> 元素可提供有關(guān)頁面的元信息(meta-information),比如針對搜索引擎和更新頻度的描述和關(guān)鍵詞。
<meta> 標(biāo)簽位于文檔的頭部,不包含任何內(nèi)容。<meta> 標(biāo)簽的屬性定義了與文檔相關(guān)聯(lián)的名稱/值對。
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 來定義列表的類型。
例子
定義針對搜索引擎的關(guān)鍵詞:
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript" />
定義對頁面的描述:
<meta name="description" content="免費的 web 技術(shù)教程。" />
定義頁面的最新版本:
<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 屬性相關(guān)的元信息。 | 4 | 5 |
http-equiv |
|
把 content 屬性關(guān)聯(lián)到 HTTP 頭部。 | 4 | 5 |
name |
|
把 content 屬性關(guān)聯(lián)到一個名稱。 | 4 | 5 |
scheme | some_text | 定義用于翻譯 content 屬性值的格式。不支持。 | 4 |
標(biāo)準(zhǔn)屬性
class, contenteditable, contextmenu, dir, draggable, id, irrelevant, lang, ref, registrationmark, tabindex, template, title
如需完整的描述,請訪問 HTML 5 中標(biāo)準(zhǔn)屬性。
事件屬性
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
如需完整的描述,請訪問 HTML 5 中事件屬性。
TIY 實例
- 文檔描述
- Meta 元素中的信息可以描述 HTML 文檔。
- 文檔關(guān)鍵字
- Meta 元素中的信息可以描述文檔的關(guān)鍵詞。
- 重定向
- 這個例子演示:在網(wǎng)址已經(jīng)變更的情況下,將用戶重定向到另外一個地址。