# Document Object Model \(DOM\)

The Document Object Model represents a web document as a tree of objects that browser code can inspect, change, and observe.

- Type: term
- Domain: Engineering & architecture
- Level: Foundational
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/document-object-model/>)

## What it means

The Document Object Model \(DOM\) is a language-neutral programming interface for documents. A browser parses HTML into a tree of nodes such as documents, elements, text, and comments; scripts use DOM interfaces to read or change structure, content, attributes, and event behavior. The DOM is a web API, not part of the JavaScript language and not identical to the HTML source.

## Why it matters

Every dynamic browser interface depends on the relationship between source markup, the live DOM, rendering, and accessibility. DOM size and mutation patterns affect performance, while incorrect structure can damage interaction and assistive-technology output.

## When to use it

Use DOM concepts when implementing or debugging browser interfaces, events, component lifecycles, testing, or accessibility. Prefer native HTML behavior and targeted updates over rebuilding large subtrees when simpler markup can provide the result.

## How it works

1. The browser parses a document and creates a hierarchy of node objects.
2. DOM interfaces expose node properties, relationships, selectors, and mutation methods.
3. Scripts attach event listeners or respond to browser-generated events.
4. Mutations update the live document and may trigger style, layout, paint, or accessibility changes.
5. Developer tools and observers reveal the resulting structure and changes.

## A practical example

A checkout script selects the shipping form, listens for a country change, and inserts the correct region field. The team verifies that the resulting DOM keeps the label association and focus order rather than merely looking correct.

## Where it breaks

The DOM does not describe pixels, network behavior, or the complete accessibility tree. Large trees and frequent layout-dependent mutations can be expensive, and a framework's virtual representation is not the browser DOM itself.

## Common mistakes

- Treating the original HTML text and the current DOM as identical.
- Calling the DOM a feature of the JavaScript language.
- Replacing large subtrees for small changes without measuring the cost.
- Assuming a visually correct DOM is automatically semantic or accessible.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/document-object-model/#visualization-document-object-model>)

## Sources

1. [DOM Standard](<https://dom.spec.whatwg.org/>) — WHATWG · Living web standard
2. [Document Object Model \(DOM\)](<https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model>) — MDN Web Docs · Official technical documentation

## Related topics

- [Critical Rendering Path](<https://wiki.soroush.uk/topic/critical-rendering-path/>)
- [Accessibility Tree](<https://wiki.soroush.uk/topic/accessibility-tree/>)
- [Semantic HTML](<https://wiki.soroush.uk/topic/semantic-html/>)
