HTML is the blueprint a browser parses to build a page’s initial user interface. The resulting DOM is related to HTML, but it is a separate representation: the browser can even correct errors in the markup while constructing it. section 4.2.1 section 4.5
During page construction:
- The browser parses HTML element by element, representing each element as a node in a tree. Nodes have one parent, may have multiple children, and can share a parent as siblings. section 4.2.1
- When the parser reaches a script tag, it normally pauses parsing to run the script, which can access and modify the DOM. The async, defer, and module attributes can override this default behavior. section 4.2
When the browser repairs markup
A paragraph placed inside the head is invalid because the head is for page information, not page content. The browser silently constructs a DOM with the paragraph in the body instead. section 4.2.1
Figure 4.2 The page-building phase starts when the browser receives the code of the page. The process of parsing HTML to build the DOM is interrupted whenever JavaScript code runs.
The diagram traces page construction and shows where JavaScript interrupts HTML parsing. section 4.2















