HTML <meta>標簽包含在網(wǎng)頁上不直接可見但由瀏覽器和搜索引擎使用的信息或元數(shù)據(jù)。該標簽通常也稱為 <meta>元素。
描述 HTML 文檔的元數(shù)據(jù):
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="The HTML meta tag is an element that resides within the HTML head tag."> <meta name="keywords" content="html, meta, tag, element"> <meta name="author" content="www.soo66.com"> <title>菜鳥教程(cainiaoplus.com)</title> </head> <body> </body> </html>測試看看 ?/?
在此HTML5文檔示例中,我們創(chuàng)建了5個meta標簽。第一個meta標簽(charset)定義HTML文檔的字符編碼。在設計響應式網(wǎng)站時,將使用第二個meta標簽(viewport)。第三個meta標簽(description)為搜索引擎的網(wǎng)頁提供了描述。第四個元標記(關鍵字)為搜索引擎提供關鍵字。最終的meta標簽(author)定義了網(wǎng)頁的作者。
IEFirefoxOperaChromeSafari
所有主流瀏覽器都支持 <meta> 標簽。
元數(shù)據(jù)(Metadata)是數(shù)據(jù)的數(shù)據(jù)信息。
<meta> 標簽提供了 HTML 文檔的元數(shù)據(jù)。元數(shù)據(jù)不會顯示在客戶端,但是會被瀏覽器解析。
META元素通常用于指定網(wǎng)頁的描述,關鍵詞,文件的最后修改時間,作者及其他元數(shù)據(jù)。
元數(shù)據(jù)可以被使用瀏覽器(如何顯示內(nèi)容或重新加載頁面),搜索引擎(關鍵詞),或其他 Web 服務調(diào)用。
注意:<meta> 標簽通常位于 <head> 區(qū)域內(nèi)。
注意: 元數(shù)據(jù)通常以 名稱/值 對出現(xiàn)。
注意: 如果沒有提供 name 屬性,那么名稱/值對中的名稱會采用 http-equiv 屬性的值。
HTML5 不支持 scheme 屬性。
在 HTML5 中,有一個新的 charset 屬性,它使字符集的定義更加容易:
HTML 4.01: <meta http-equiv="content-type" content="text/html; charset=UTF-8">
HTML5: <meta charset="UTF-8">
在 HTML 中 <meta> 標簽沒有結束標簽。
在 XHTML 中 <meta> 標簽必須包含結束標簽。
示例 1 - 定義文檔關鍵詞,用于搜索引擎:
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
示例 2 - 定義web頁面描述:
<meta name="description" content="Free Web tutorials on HTML and CSS">
示例 3 - 定義頁面作者:
<meta name="author" content="nhoo.com">
示例 4 - 每30秒刷新頁面:
<meta http-equiv="refresh" content="30">
New :HTML5 新屬性。
屬性 | 值 | 描述 |
---|---|---|
charsetHTML5 | character_set | 定義文檔的字符編碼。 |
content | text | 定義與 http-equiv 或 name 屬性相關的元信息。 |
http-equiv | content-type default-style refresh | 把 content 屬性關聯(lián)到 HTTP 頭部。 |
name | application-name author description generator keywords | 把 content 屬性關聯(lián)到一個名稱。 |
scheme | format/URI | HTML5不支持。 定義用于翻譯 content 屬性值的格式。 |
<meta> 標簽支持所有 HTML事件屬性。
HTML 教程:HTML 頭部