Description
The HTML element <head>
is used to define the head section of an HTML document, which is used to define the document's metadata.
It must be the first child of the <html>
element and must be defined only once.
Though the <head>
element is optional, it is always suggested to define and include required metadata.
Here is a list of all the elements that the head section can contain.
- Element <title> defines the document title
- Element <base> defines the document base URL that will be used to resolve all the reference URLs
- Element <meta> defines metadata
- Element <link> defines relationship with external resources linked
- Element <style> defines styles for the specific document level
- Element <script> defines scripts for the specific document level
- Element <noscript> defines alternative content to be displayed on browsers that doesn't support scripts or scripts diabled.
The below table summarizes its usage.
Usage Details | |
Placement | It must be the first child of <html> element. |
Contents | It can contain the elements <title> , <base> , <meta> , <link> , <style> , <script> , <noscript> . |
Tags | Both opening and closing tags are required. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <head>
element.
<head>...</head>
Examples
In the below example, the <head>
element is used to define the head section.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Document head goes here -->
</head>
<body>
<!-- Document body goes here -->
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <head>
tag.
Attribute Type | Details |
Element-Specific Attributes | The tag <head> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <head> supports the HTML Global Attributes. |
Event Attributes | The tag <head> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <head>
element.
Attribute | Value | Description |
profile | URL | Obsolete and not to be used. Specifies the location of one or more metadata profiles with a white space between them. |
Browser Compatibility
The tag <head>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 2.1+