Favorites

DOM Document Interface

☕
Enjoying this site?

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

Buy us a coffee
Document
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

The Document interface represents the whole web page loaded in the browser. The global document object is your starting point for finding, creating and changing elements.

Description

The Document interface represents a web page loaded in the browser and is the entry point to the DOM tree. The global document object gives you the page's <html>, <head> and <body> elements, methods to find elements (getElementById(), querySelector()) and create them (createElement()), and information such as the title, URL, readyState and cookie.

It inherits from Node and EventTarget, so you can listen for document-level events such as DOMContentLoaded, visibilitychange and keyboard events.

Besides the main page, a Document can represent the content of an iframe (through iframe.contentDocument), a document created with document.implementation.createHTMLDocument(), or an HTML or XML document parsed with DOMParser. Methods such as createElement() create nodes that belong to a particular document, which is why you normally use the global document to create elements for the page.

Inheritance

Document inherits properties and methods from Node.

Properties

NameDescription
Document.activeElementThe activeElement property returns the element that currently has keyboard focus.
Document.bodyThe body property returns the page's body element.
Document.cookieThe cookie property reads all cookies for the page as one string, or writes a single cookie when assigned.
Document.documentElementThe documentElement property returns the root element of the page, the html element.
Document.headThe head property returns the page's head element, where you can add style sheets, scripts and meta tags with JavaScript.
Document.readyStateThe readyState property tells you how far the page has loaded: loading, interactive or complete.
Document.titleThe title property gets or sets the page title shown in the browser tab.

Methods

NameDescription
Document.createDocumentFragment()The createDocumentFragment() method creates an empty DocumentFragment, an off-screen container for building groups of elements.
Document.createElement()The createElement() method creates a new HTML element, which you can then fill in and add to the page.
Document.getElementById()The getElementById() method finds the element with a given id.
Document.querySelector()The document.querySelector() method returns the first element in the page that matches a CSS selector, or null.
Document.querySelectorAll()The document.querySelectorAll() method returns a list of every element in the page that matches a CSS selector.

Events

NameDescription
Document: DOMContentLoaded eventThe DOMContentLoaded event fires when the HTML has been fully parsed and the DOM is ready, without waiting for images and style sheets to load.

Example

<p>Existing paragraph</p>
console.log(document.title);
console.log(document.documentElement.tagName, document.body.tagName);
console.log(document.readyState);
const p = document.createElement('p');
p.textContent = 'Added with JavaScript';
document.body.append(p);
console.log(document.querySelectorAll('p').length);

Browser Support

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

This interface 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