Definition and Usage
The <head> tag contains a collection of elements related to document metadata
such as character encoding, titles, descriptions, stylesheets, and scripts.
This information is not visible on the screen, but is essential for machine processing by browsers, search engines, and other web technologies.
Here, document information (metadata) refers to additional encoded information required to manage and technically process an HTML document.
Basic Example
To understand the <head> tag, you need to understand the basic structure of HTML.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> <!-- Character encoding -->
<title>The title of this page</title> <!-- Document title -->
<meta name="description" content="A short description of this page."> <!-- Document description -->
<link rel="stylesheet" href="style.css"> <!-- Stylesheet -->
<script src="script.js"></script> <!-- Script -->
</head>
<body>
<!-- The document's content -->
</body>
</html>
<!DOCTYPE html>: This part declares the document type and serves to ensure that the browser follows the latest web standards and renders the document correctly. It is not an HTML element.<html>: The root element, which is the top-level element of an HTML document. All HTML elements must be contained within the<html>element.<head>: This part defines the metadata and header information of the HTML document. It provides information about the document to the browser and can be used to link external stylesheets, JavaScript files, and more.<body>: This part defines the body content of the HTML document. The content that is actually displayed on the web page is written in this section, and various elements such as text, images, links, tables, and forms can be included.
The primary purpose of the <head> tag is to collect HTML document information (metadata) for machine processing by browsers, search engines, and other web technologies.
Since this tag is not displayed on the screen,
if you need to display the document's main heading or author information on the screen, use the <header> tag instead.
Technical Summary
The <head> tag is a required tag that is essential for the basic structure of HTML.
A standards-compliant HTML document must contain only one <head> tag.
The <head> tag must be the first child element of the <html> element.
The title provided by the <title> element is used as the title displayed in the browser’s title bar or page tab.
It is also read by screen readers for users with visual impairments, making it essential information that must be provided for web accessibility.
The following table summarizes the technical syntax of the <head> tag.
| Permitted parents | It must be the first child element of the <html> element. |
|---|---|
| Permitted content |
|
Implicit ARIA role |
No corresponding role |
Permitted ARIA roles |
No role permitted |
Incorrect Markup Examples
The following are examples of incorrect markup using the <head> tag.
Invalid HTML Structure
<!DOCTYPE html>
<html>
<body>
<head> <!-- Invalid HTML structure -->
<!-- Document information (metadata) -->
</head>
<!-- Document content -->
</body>
</html>
The <head> tag is an essential element that forms the basic structure of an HTML document.
The <head> tag must always be the first child element of the <html> element.
The <title> Element Must Be Present as a Child Element
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- The <title> tag representing the document title is missing -->
<meta name="description" content="A short description of this page.">
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<!-- The document's content -->
</body>
</html>
In this example, the <head> tag is missing the <title> tag, which is required to represent the document title.
Specifications
| Specification | |
|---|---|
<head>
|
HTML Standard #the-head-element |
Browser Compatibility
| Tag |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
<head>
|
1 | 12 | 1 | 1 |
See Also
- HTML <html> Tag – The Document Root Element
- HTML <body> Tag – The Document Body Element
- HTML <title> Tag – The Document Title Element
- HTML <style> Tag – The Style Information Element
- HTML <link> Tag – The External Resource Link Element
- HTML <script> Tag – The Script Element
- HTML <meta> Tag – The Metadata Element