Document.documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).

Syntax

var element = document.documentElement;

Example

var rootElement = document.documentElement;
var firstTier = rootElement.childNodes;

// firstTier is the NodeList of the direct children of the root element
for (var i = 0; i < firstTier.length; i++) {
   // do something with each direct kid of the root element
   // as firstTier[i]
}

Notes

For any non-empty HTML document, document.documentElement will always be an <html> element. For any non-empty XML document, document.documentElement will always be whatever element is the root element of the document.

Specifications

Specification Status Comment
DOM
The definition of 'Document.documentElement' in that specification.
Living Standard  
DOM4
The definition of 'Document.documentElement' in that specification.
Obsolete  
Document Object Model (DOM) Level 3 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete  
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: mfuji09,