If you find this helpful, please click the Google Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.) |
The <head> Tag in HTML 5
The <head> tag creates the head section of the document, which contains the HTML page title that appears in the title bar of the web browser window plus other metadata information describing the document and possibly linking to other related resources. The head element is the first of the two elements making up the inner HTML of the top html element, preceding the <body> start tag for the body section, which is created by the body element in the top html element inner HTML. The <head> tag is one of the structure tags in HTML.
<head> Tag Syntax
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/site-template.xsl"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ... metadata content ... <title>... text content ...</title> ... </head> <body> ... flow content ... </body> </html>
Rules for coding the HTML head element
Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.
- Code the head element for the head section as the first element in the content of the html element.
- Begin the head element with a starting <head> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlns
attribute on the <html> tag. - Include a single, required title element inside the head element.
- Include any other optional head section content, such as <script> tags, <meta/> tags, <link> tags and <style> tags.
- End the head element with a matching </head> closing tag.
- After the head element, a body element is the only other non-whitespace content inside the html element.
<head> Tag Content Model
Contents of the <head>...</head> Element
The content of the head element is expected to be metadata content with some restrictions. Therefore, the following metadata elements can be coded between the starting <head> tag and the ending </head> tag:
HTML Tag | Content of <head>...</head> Element |
---|---|
<title> required | a single required title element with the title that is to appear in the browser's address bar |
<base/> | an optional base element |
<command/> | optional command element(s) |
<link/> | optional link element(s) |
<meta/> | optional meta element(s) |
<noscript> | optional noscript element(s) |
<script> | optional script element(s) |
<style> | optional style element(s) |
<rdf:RDF> | optional RDF element(s) |
<!--comments--> | possibly interspersed with HTML comments |
<head> Tag Attributes
Attributes of the <head> tag
global attributes | The only attributes that can be coded on the <head> tag are the common HTML attributes. |
<head> Tag Examples
Examples of the head
tag in HTML 5
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/site-template.xsl"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="application/xslt+xml" href="/site-template.xsl"/> <title>Example Only</title> </head> <body> ... </body> </html>
Changes in HTML 5 - <head> Tag
What's new in HTML 5
Differences between HTML 5 and earlier versions of HTML
The <object>
tag is not allowed in the head section.
The 2000-2010 Recommendations from the W3C HTML Working Group defined the HTML namespace for the head element type name along with the names of all HTML element types. In older (pre-2000) versions of HTML, element type names were not associated with a namespace.