# HTML <head> 標簽
## 實例
一個簡單的 HTML 文檔,帶有最基本的必需的元素:
```
<html>
<head>
<title>文檔的標題</title>
</head>
<body>
文檔的內容... ...
</body>
</html>
```
## 瀏覽器支持
| IE | Firefox | Chrome | Safari | Opera |
| --- | --- | --- | --- | --- |
所有瀏覽器都支持 <head> 標簽。
## 定義和用法
<head> 標簽用于定義文檔的頭部,它是所有頭部元素的容器。<head> 中的元素可以引用腳本、指示瀏覽器在哪里找到樣式表、提供元信息等等。
文檔的頭部描述了文檔的各種屬性和信息,包括文檔的標題、在 Web 中的位置以及和其他文檔的關系等。絕大多數文檔頭部包含的數據都不會真正作為內容顯示給讀者。
下面這些標簽可用在 head 部分:[<base>](/tags/tag_base.asp "HTML <base> 標簽"), [<link>](/tags/tag_link.asp "HTML <link> 標簽"), [<meta>](/tags/tag_meta.asp "HTML <meta> 標簽"), [<script>](/tags/tag_script.asp "HTML <script> 標簽"), [<style>](/tags/tag_style.asp "HTML <style> 標簽"), 以及 [<title>](/tags/tag_title.asp "HTML <title> 標簽")。
<title> 定義文檔的標題,它是 head 部分中唯一必需的元素。
## 提示和注釋
提示:應該把 <head> 標簽放在文檔的開始處,緊跟在 <html> 后面,并處于 <body> 標簽或 <frameset> 標簽之前。
提示:請記住始終為文檔規定標題!
## HTML 與 XHTML 之間的差異
NONE
## 可選的屬性
| 屬性 | 值 | 描述 |
| --- | --- | --- |
| profile | _URL_ | 一個由空格分隔的 URL 列表,這些 URL 包含著有關頁面的元數據信息。 |
### profile 屬性的更多信息
文檔的頭部經常會包含一些 <meta> 標簽,用來告訴瀏覽器關于文檔的附加信息。在將來,創作者可能會利用預先定義好的標準文檔的元數據配置文件(metadata profile),以便更好地描述它們的文檔。profile 屬性提供了與當前文檔相關聯的配置文件的 URL。
配置文件的格式以及瀏覽器使用它們的方式都還沒有進行定義,這個屬性主要是為將來的開發而保留的占位符。
## 全局屬性
<head> 標簽支持 [HTML 中的全局屬性](/tags/html_ref_standardattributes.asp)。
## TIY 實例
[文檔的標題](/tiy/t.asp?f=html_title)
頭元素內部的標題信息不會被顯示在瀏覽器窗口中。
```
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>標題不會顯示在文檔區</title>
</head>
<body>
<p>這段文本會顯示出來。</p>
</body>
</html>
```
[一個 target,所有的鏈接](/tiy/t.asp?f=html_base)
本例顯示如何使用 base 標簽使頁面中的所有標簽在新窗口中打開。
```
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<base target="_blank" />
</head>
<body>
<p>
<a href="http://www.w3school.com.cn" target="_blank">這個連接</a> 將在新窗口中加載,因為 target 屬性被設置為 "_blank"。
</p>
<p>
<a href="http://www.w3school.com.cn">這個連接</a> 也將在新窗口中加載,即使沒有 target 屬性。
</p>
</body>
</html>
```
[HTML 中的樣式](/tiy/t.asp?f=html_style)
本例演示如何使用添加到 <head> 部分的樣式信息對 HTML 進行格式化。
```
<html>
<head>
<style type="text/css">
h1 {color: red}
p {color: blue}
</style>
</head>
<body>
<h1>header 1</h1>
<p>A paragraph.</p>
</body>
</html>
```
[鏈接到一個外部樣式表](/tiy/t.asp?f=html_link)
本例演示如何通過 <link> 標簽鏈接到一個外部樣式表。
```
<html>
<head>
<link rel="stylesheet" type="text/css" href="/html/csstest1.css" >
</head>
<body>
<h1>我通過外部樣式表進行格式化。</h1>
<p>我也一樣!</p>
</body>
</html>
```
[文檔描述](/tiy/t.asp?f=html_meta)
Meta 元素中的信息可以描述 HTML 文檔。
```
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="author"
content="w3school.com.cn">
<meta name="revised"
content="David Yang,8/1/07">
<meta name="generator"
content="Dreamweaver 8.0en">
</head>
<body>
<p>本文檔的 meta 屬性標識了創作者和編輯軟件。</p>
</body>
</html>
```
[文檔關鍵字](/tiy/t.asp?f=html_keywords)
Meta 元素中的信息可以描述文檔的關鍵詞。
```
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="description"
content="HTML examples">
<meta name="keywords"
content="HTML, DHTML, CSS, XML, XHTML, JavaScript, VBScript">
</head>
<body>
<p>本文檔的 meta 屬性描述了該文檔和它的關鍵詞。</p>
</body>
</html>
```
[重定向](/tiy/t.asp?f=html_redirect)
這個例子演示:在網址已經變更的情況下,將用戶重定向到另外一個地址。
```
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn" />
</head>
<body>
<p>
對不起。我們已經搬家了。您的 URL 是 <a href="http://www.w3school.com.cn">http://www.w3school.com.cn</a>
</p>
<p>您將在 5 秒內被重定向到新的地址。</p>
<p>如果超過 5 秒后您仍然看到本消息,請點擊上面的鏈接。</p>
</body>
</html>
```
- HTML 標簽列表
- HTML <!--...--> 標簽
- HTML <!DOCTYPE> 標簽
- HTML <a> 標簽
- HTML <abbr> 標簽
- HTML <acronym> 標簽
- HTML <address> 標簽
- HTML <applet> 標簽
- HTML <area> 標簽
- HTML <article> 標簽
- HTML <aside> 標簽
- HTML <audio> 標簽
- HTML <b> 標簽
- HTML <base> 標簽
- HTML <basefont> 標簽
- HTML <bdi> 標簽
- HTML <bdo> 標簽
- HTML <big> 標簽
- HTML <blockquote> 標簽
- HTML <body> 標簽
- HTML <br> 標簽
- HTML <button> 標簽
- HTML <canvas> 標簽
- HTML <caption> 標簽
- HTML <center> 標簽
- HTML <cite> 標簽
- HTML <em> <strong> <dfn> <code> <samp> <kbd><var> <cite> 標簽
- HTML <col> 標簽
- HTML <colgroup> 標簽
- HTML <command> 標簽
- HTML <datalist> 標簽
- HTML <dd> 標簽
- HTML <del> 標簽
- HTML <details> 標簽
- HTML <dialog> 標簽
- HTML <dir> 標簽
- HTML <div> 標簽
- HTML <dl> 標簽
- HTML <dt> 標簽
- HTML <embed> 標簽
- HTML <fieldset> 標簽
- HTML <figcaption> 標簽
- HTML <figure> 標簽
- HTML <font> 標簽
- HTML <footer> 標簽
- HTML <form> 標簽
- HTML <frame> 標簽
- HTML <frameset> 標簽
- HTML <h1> 到 <h6> 標簽
- HTML <head> 標簽
- HTML <header> 標簽
- HTML <hr> 標簽
- HTML <html> 標簽
- HTML <i> 標簽
- HTML <iframe> 標簽
- HTML <img> 標簽
- HTML <input> 標簽
- HTML DOM Button 對象
- HTML DOM Checkbox 對象
- HTML DOM Color 對象
- HTML DOM Input Date 對象
- HTML DOM Datetime 對象
- HTML DOM Datetime Local 對象
- HTML DOM Email 對象
- HTML DOM FileUpload 對象
- HTML DOM Hidden 對象
- HTML DOM Input Image 對象
- HTML DOM Month 對象
- HTML DOM Number 對象
- HTML DOM Password 對象
- HTML DOM Input Range 對象
- HTML DOM Radio 對象
- HTML DOM Reset 對象
- HTML DOM Input Search 對象
- HTML DOM Submit 對象
- HTML DOM Text 對象
- HTML DOM Input Time 對象
- HTML DOM Input URL 對象
- HTML DOM Input Week 對象
- HTML <ins> 標簽
- HTML <keygen> 標簽
- HTML <label> 標簽
- HTML <legend> 標簽
- HTML <li> 標簽
- HTML <link> 標簽
- HTML <main> 標簽
- HTML <map> 標簽
- HTML <mark> 標簽
- HTML <menu> 標簽
- HTML <menuitem> 標簽
- HTML <meta> 標簽
- HTML <meter> 標簽
- HTML <nav> 標簽
- HTML <noframes> 標簽
- HTML <noscript> 標簽
- HTML <object> 標簽
- HTML <ol> 標簽
- HTML <optgroup> 標簽
- HTML <option> 標簽
- HTML <output> 標簽
- HTML <p> 標簽
- HTML <param> 標簽
- HTML <pre> 標簽
- HTML <progress> 標簽
- HTML <q> 標簽
- HTML <rp> 標簽
- HTML <rt> 標簽
- HTML <ruby> 標簽
- HTML <s> 標簽
- HTML <script> 標簽
- HTML <section> 標簽
- HTML <select> 標簽
- HTML <small> 標簽
- HTML <source> 標簽
- HTML <span> 標簽
- HTML <strike> 標簽
- HTML <style> 標簽
- HTML <sub> 標簽
- HTML <summary> 標簽
- HTML <sup> 標簽
- HTML <table> 標簽
- HTML <tbody> 標簽
- HTML <td> 標簽
- HTML <textarea> 標簽
- HTML <tfoot> 標簽
- HTML <th> 標簽
- HTML <thead> 標簽
- HTML <time> 標簽
- HTML <title> 標簽
- HTML <tr> 標簽
- HTML <track> 標簽
- HTML <tt> 標簽
- HTML <u> 標簽
- HTML <ul> 標簽
- HTML <video> 標簽
- HTML <wbr> 標簽
- HTML 全局屬性
- HTML accesskey 屬性
- HTML class 屬性
- HTML contenteditable 屬性
- HTML contextmenu 屬性
- HTML data-* 屬性
- HTML dir 屬性
- HTML draggable 屬性
- HTML dropzone 屬性
- HTML hidden 屬性
- HTML id 屬性
- HTML lang 屬性
- HTML spellcheck 屬性
- HTML style 屬性
- HTML tabindex 屬性
- HTML title 屬性
- HTML translate 屬性
- HTML 事件屬性
- HTML 5 視頻/音頻參考手冊
- HTML 5 Canvas 參考手冊
- HTML 元素和有效的 DTD
- HTML 顏色名
- HTML 字符集
- HTML ASCII 參考手冊
- HTML ISO-8859-1 參考手冊
- HTML 4.01 符號實體
- HTML URL 編碼
- HTML 語言代碼參考手冊
- HTTP 狀態消息
- HTTP 方法:GET 對比 POST
- 免責聲明