Head
<head>
Element
The <head>
element is a container for metadata (data about data). (所有头部元素的容器)
HTML metadata is data about the HTML document. Metadata is not displayed. Metadata typically define document title, styles, links, scripts, and other meta information.
The following tags describe metadata: <title>
, <style>
, <meta>
, <link>
, <script>
, and <base>
.
Omitting <html>
and <body>
In the HTML5 standard, the tag, the tag, and the tag can be omitted.
<!DOCTYPE html>
<title>Page Title</title>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
NOT recommend. Omitting <html>
and <body>
can crash badly-written DOM/XML software. Finally, omitting can produce errors in older browsers (IE9).
Omitting<head>
In the HTML5 standard, the <head>
tag can also be omitted.
By default, browsers will add all elements before <body>
, to a default <head>
element.
You can reduce the complexity of HTML, by omitting the <head>
tag:
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<title>
Element
The <title>
element defines the title of the document.
The <title>
element is required in all HTML/XHTML documents.
The <title>
element:
- defines a title in the browser tab
- provides a title for the page when it is added to favorites
- displays a title for the page in search engine results
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
The content of the document......
</body>
</html>
<style>
Element
The <style>
element is used to define style information for an HTML document. Inside the <style>
element you specify how HTML elements should render in a browser:
<style>
body {background-color:yellow;}
p {color:blue;}
</style>
<link>
Element
The <link>
element defines the page relationship to an external resource. The <link>
element is most often used to link to style sheets:
<link rel="stylesheet" href="mystyle.css">
<meta>
Element
The <meta>
element is used to specify page description, keywords, author, and other metadata.
Metadata is used by browsers (how to display content), by search engines (keywords), and other web services.
Define keywords for search engines:
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
Define a description of your web page:
<meta name="description" content="Free Web tutorials on HTML and CSS">
Define the character set used:
<meta charset="UTF-8">
Define the author of a page:
<meta name="author" content="Hege Refsnes">
Refresh document every 30 seconds:
<meta http-equiv="refresh" content="30">
Example:
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Hege Refsnes">
<meta charset="UTF-8">
<script>
Element
The <script>
element is used to define client-side JavaScripts.
<script>
function myFunction {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
Writes Hello JavaScript! into an HTML element with id="demo"
<base>
Element
The <base>
element specifies the base URL and base target for all relative URLs in a page:
<base href="http://www.w3schools.com/images/" target="_blank">
(为页面上的所有链接规定默认地址或默认目标)
head Elements
Tag | Description |
---|---|
<head> |
Defines information about the document |
<title> |
Defines the title of a document |
<base> |
Defines a default address or a default target for all links on a page |
<link> |
Defines the relationship between a document and an external resource |
<meta> |
Defines metadata about an HTML document |
<script> |
Defines a client-side script |
<style> |
Defines style information for a document |