HTML parsing
Bytes become tokens. Tokens become nodes. Nodes become a tree.
Bytes
<html>
<head>
<title>Hi</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>DOM tree
The HTML parser chews through the byte stream and emits tokens for tags, attributes and text. The parser is forgiving by design, broken markup gets quietly patched rather than rejected, so almost any input still produces a tree. Each token becomes a node, and nodes are stitched into the DOM in the order the parser meets them.
Parsing is interleaved with resource discovery. When the parser encounters <link rel="stylesheet"> or <script>, it kicks off downloads in parallel, but a synchronous <script> blocks parsing until it executes, because the script can mutate the DOM as it runs (for example, with document.write).
Takeaway
Parsing is incremental. The DOM grows in chunks as bytes arrive, and any blocking script puts a pause on the whole construction process.