Favorites

DOM Document.documentElement Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Document.documentElement
DOM Document PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The documentElement property returns the root element of the page, the html element.

Description

The read-only documentElement property returns the document's root element, the <html> element in a web page. It's where you set page-wide attributes such as lang, theme classes or data-theme, and where you set CSS custom properties that apply everywhere (it matches the :root selector).

It's also the element to measure for page-wide dimensions: document.documentElement.clientWidth gives the viewport width without scroll bars, and scrollHeight gives the full height of the page.

Setting the lang attribute on it, document.documentElement.lang = 'fr', tells screen readers and translation tools which language the page is in, which is important when a single-page application switches languages.

Syntax

document.documentElement

Value

The root element of the document, <html> for HTML pages.

Example

<p style="color:var(--brand)">Brand coloured text</p>
const root = document.documentElement;
console.log(root.tagName);
root.style.setProperty('--brand', 'teal');
root.dataset.theme = 'dark';
console.log(root.outerHTML.slice(0, 60));

Browser Support

The following information will show you the current browser support for the Document.documentElement property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee