Document Object Model
Also known as: DOM
Programming interface that represents a web page as a tree of objects, letting scripts read and change its content, structure and style.
The Document Object Model (DOM) is the in-memory representation of a web page that browsers build from its HTML. Every element, attribute and piece of text becomes a node in a tree: the document node at the top contains the html element, which contains head and body, which in turn contain headings, paragraphs, images and so on. The DOM is also an API, a set of standard methods that programs, usually written in JavaScript, use to find nodes, change their text or attributes, add or remove elements and respond to events such as clicks and key presses.
In the 1990s, Netscape and Microsoft each gave scripts different and incompatible ways to manipulate pages, a period remembered for browser incompatibilities. The World Wide Web Consortium published DOM Level 1 as a recommendation in 1998 to define a common, language-neutral interface, followed by further levels. Maintenance later moved to the WHATWG, which publishes the DOM as a continuously updated living standard. Every interactive web page relies on DOM manipulation, from a menu that opens when clicked to a form that validates input as it is typed.
Changing the DOM can be expensive, because each change may force the browser to recalculate layout and repaint the page. This cost motivated libraries such as React, which compute changes against a lightweight copy of the tree, often called a virtual DOM, and apply only the differences. The DOM is also a security boundary: inserting untrusted text into a page as HTML lets attackers run scripts, the basis of DOM-based Cross-Site scripting, which is why safe APIs treat user input as plain text. Assistive technologies rely on an accessibility tree that browsers derive from the DOM.
Key points
- The DOM represents a web page as a tree of nodes built from its HTML.
- Scripts use the DOM API to read and modify page content and to respond to user events.
- The W3C first standardized the DOM in 1998, and the WHATWG maintains it as a living standard.
- Inserting untrusted content into the DOM as HTML can enable cross-site scripting attacks.
Related entries
HTML
Markup language used to structure content on the World Wide Web, describing headings, paragraphs, links, images and interactive elements.
JavaScript
High-level programming language of the web, created at Netscape in 1995, that runs in every major browser and on servers through runtimes like Node.js.
CSS
Style sheet language that controls the layout, colors, typography and visual presentation of HTML documents on the web.
React
Open-source JavaScript library from Meta for building user interfaces out of reusable components that update efficiently when data changes.
Single-Page Application
Web application that loads a single HTML page and then updates its content with JavaScript instead of loading fresh pages from the server.
Cross-Site Scripting
Web vulnerability that lets attackers inject malicious scripts into pages viewed by other users, which then run with the trust of the affected site.
World Wide Web Consortium
International standards organization that develops open technical standards and guidelines for the World Wide Web, including CSS and accessibility guidelines.
Web Accessibility
Practice of designing and building websites and apps so that people with disabilities can perceive, understand and operate them fully.
Referenced by
Other entries that discuss or point to Document Object Model.