HTML vs DOM
People think the DOM is the HTML file, and it is not. The HTML file is the text the server sends. The DOM is the live tree the browser builds from it. Scripts change the DOM, not the file. So the page on screen can differ from the page source.
HyperText Markup Language (HTML)
The language that sets out what is on a web page, using tags.
HTML is the language that says what is on a web page. It wraps each piece of content in tags, like <h1> for a heading or <a> for a link. The browser reads the tags and shows the page. HTML gives the page its structure, CSS gives it looks and JavaScript makes it act. Every web page starts as HTML.
Document Object Model (DOM)
The browser's live tree of a page. JavaScript can read it and change it.
The DOM is the browser's live copy of a web page, held as a tree of parts. When a page loads, the browser turns the HTML into this tree. JavaScript can then find any part, change its text, add new parts or remove old ones. The page on screen updates to match. Every interactive web page works by changing the DOM.
In one line
- HyperText Markup Language (HTML)
- The language that sets out what is on a web page, using tags.
- Document Object Model (DOM)
- The browser's live tree of a page. JavaScript can read it and change it.