BOM and DOM
Learn the difference between the Browser Object Model (BOM) and the Document Object Model (DOM), and how to access them in JavaScript.
Learn the difference between the Browser Object Model (BOM) and the Document Object Model (DOM), and how to access them in JavaScript.
When JavaScript runs in a browser, it has access to two environments: the BOM and the DOM.
The DOM represents the HTML structure of your page as a tree of objects. Every element — <div>, <p>, <button> — becomes a node you can select, read, and modify.
document.querySelector("h1").textContent = "New title";document is the entry point to the DOM. Everything visible on the page lives here.
The BOM represents the browser itself — things outside the document: the window, URL, history, and screen.
window.innerWidth; // viewport width in pixelswindow.location.href; // current URLwindow.location.reload(); // reload the pagewindow.history.back(); // go backwindow.scrollTo(0, 0); // scroll to topwindow is the global object in browsers. Any variable you declare at the top level becomes a property of window, which is why console.log and setTimeout work without importing anything — they live on window.
The DOM is technically part of the BOM — document is a property of window:
window.document === document; // trueIn practice, people use “DOM” to mean page structure and “BOM” to mean browser features. The distinction helps you know what you’re dealing with.
| What it represents | Entry point | |
|---|---|---|
| DOM | Page content | document |
| BOM | Browser features | window |