<head>


HTML <head> Tag

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>

<body>
文档内容......
</body>

</html>

Run Example»

Click the "Run Instance" button to view the online instance


Browser support

1000.png

##All major browsers support the <head> tag .


Tag definition and usage instructions

The<head> element is the container for all head elements. The

<head> element must contain the title of the document and can contain scripts, styles, meta information and more.

The elements listed below can be used inside the <head> element:

  • <title> (In the head, this element is required)

  • <style>

  • ##<base>
  • ##<link>
  • <meta>
  • ##<script>

  • ##<noscript>

  • Differences between HTML 4.01 and HTML5

  • HTML5 no longer supports the profile attribute.

Properties


Properties

ValueDescriptionprofileURL
HTML5 Not supported. A series of rules that specify document URLs. These rules are recognized by the browser and accurately read the information in the content attribute of the <meta> tag.



Global attributes

The<head> tag supports HTML global attributes.

Try it - Example

Using the <base> tag in <head>
This example demonstrates how to use the <base> tag to specify the page Default URL and default target for all links.

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title>
<base href="http://www.php.cn//images/" target="_blank">
</head>
<body>

<p><img src="logo.png" > - 注意这里我们设置了图片的相对地址。能正常显示是因为我们在 head 部分设置了 base 标签,该标签指定了页面上所有链接的默认 URL,所以该图片的访问地址为 "http://www.php.cn/images/logo.png"</p>

<p><a href="http://www.php.cn/">php.cn</a> - 注意这个链接会在新窗口打开,即便它没有 target="_blank" 属性。因为在 base 标签里我们已经设置了 target 属性的值为 "_blank"。</p>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance

Using the <style> tag in <head>
This example demonstrates how to add style information in the <head> section.

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title>
<style type="text/css">
h1 {color:red;}
p {color:blue;}
</style>
</head>

<body>
<h1>这是一个标题</h1>
<p>这是一个段落。</p>
</body>

</html>

Run instance»

Click the "Run instance" button to view the online instance

Using the <link> tag in <head>
This example demonstrates how to use the <link> tag to link to an external style sheet.

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title>
<link rel="stylesheet" type="text/css" href="styles.css"> 
</head>

<body>
<h1>我是通过样式文件 styles.css 渲染后显示的。</h1>
<p>我也是。</p>
</body>

</html>

Run instance»

Click the "Run instance" button to view the online instance


Related Articles

HTML Tutorial: HTML Header