Caffeinated Coder
Book an appointment
Lesson 11 · How browsers use HTML

From HTML to the DOM tree

A browser never draws your HTML file directly. It first turns the file's bytes into characters, the characters into tokens, and the tokens into a tree of objects in memory: the DOM. Follow a five-line file through the real parsing rules of the HTML standard and watch the stack of open elements push and pop as the tree grows. On the way, the parser adds the html, head and body elements the file left out and closes a paragraph it left open. Then a line of JavaScript changes the tree while the file stays the same.

12 min11 steps5 questionsAdvanced
Fig 11 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.