HTML DOM Document head attribute

Definition and usage

head This property returns the document's <head> element.

Tip

If there is no <head> element, HTML will add an empty element.

If there are multiple <head> elements, this property returns the first one.

See also:

HTML DOM Head Object

HTML <head> Tag

Instance

Example 1

Get the tag name of the <head> element:

document.head.tagName;

Try it yourself

Example 2

Try using a document without a <head> element:

document.head.tagName;

Try it yourself

Example 3

Get the tag name of the first child element of the <head> element:

document.head.firstElementChildtagName;

Try it yourself

Example 4

You can also use getElementsByTagName("head") to access the <head> element:

getElementsByTagName("head")[0].tagName;

Try it yourself

Syntax

document.head

Return value

Type Description
Node The document's head element.

Browser support

document.head It is a feature of DOM Level 3 (2004).

All browsers support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support