The Document Object Model (DOM) is what a browser makes of a page's HTML. As it reads the HTML, it builds a tree of objects, one for each element, piece of text and attribute, and draws the page from that tree. Scripts can read and change the tree, and the page on screen changes with it.
So the HTML file is the recipe the server sends. The DOM is the page as it stands in the browser right now, including everything JavaScript has added or removed since it loaded.
What the DOM tree looks like
Take this small piece of HTML:
<body>
<h1>Garden tools</h1>
<p>Spades, rakes and <a href="/hoes">hoes</a>.</p>
</body>
The browser turns it into a tree of nodes (the real tree also keeps the line breaks and spaces as text nodes, left out here):
body
├── h1
│ └── "Garden tools"
└── p
├── "Spades, rakes and "
├── a (href="/hoes")
│ └── "hoes"
└── "."
At the top of every tree sits the document object, the root. Under it are element nodes such as body and p, and text nodes with the actual words. People often call all nodes "elements", but strictly a text node isn't an element.
Scripts reach the tree through the DOM's interface. For example, document.querySelector("h1").textContent = "Hand tools" changes the heading on screen without reloading the page.
The DOM isn't JavaScript
The DOM is a Web API, a standard interface that browsers provide. It isn't part of the JavaScript language: JavaScript running outside a browser, in Node.js for example, has no DOM by default. Other languages can work with a DOM too. The standard is maintained by WHATWG as the DOM Living Standard.
Source code vs the DOM
What you see depends on where you look:
- View page source shows the HTML the server sent, before any script ran.
- Inspect (the Elements panel in developer tools) shows the current DOM, after scripts have changed it.
On a simple static page the two look almost the same. On a page built with JavaScript, the source can be nearly empty while the DOM holds the full article, menu and links.
Why the DOM matters for SEO
Google doesn't index only your source HTML. It crawls the page, then renders it in an up-to-date version of Chromium, and indexes the rendered HTML: in effect, the DOM after JavaScript has run. Rendering can happen seconds after crawling, or later. Google Search Central
That has practical consequences:
- Content added by JavaScript can be indexed, as long as it ends up in the rendered DOM and Google can fetch the scripts.
- Links need to be real links. Google follows
<a>elements with anhrefattribute. A click handler on adivorspanisn't a link to Google. - JavaScript can set the title and meta description, and Google can use what it renders.
- Put the canonical in the HTML. If JavaScript sets a canonical tag, it should match the one in the original HTML.
- A noindex in the original HTML may stick. Google may skip rendering such a page, so removing noindex with JavaScript might never be seen.
Google itself recommends server-side rendering or pre-rendering where you can: pages load faster for people and crawlers, and not every bot runs JavaScript. See web rendering for how these approaches differ.
How to check what Google sees
Compare the page source with the Elements panel first. If important text or links appear only in the DOM, they depend on JavaScript.
Then use the URL Inspection tool in Google Search Console. Its live test shows a screenshot of the page as Google renders it, so you can see whether your content made it into the rendered page.