Short answer
HTML does not run like a program. The browser fetches bytes, tokenizes them, builds a document tree, applies CSS, then lays out and paints. The HTML standard says the parse input is a stream of code points and the output is a Document. MDN splits the path into DOM, CSSOM, style, layout, and paint. This page does not invent a millisecond time for that parse.
Last verified against the sources listed below.
Key takeaways
- Parsing is tokenization, then tree construction. The output is a Document.
- Tokens include doctype, start tag, end tag, comment, character, and end of file.
- MDN's rendering path is DOM, CSSOM, render tree, layout, then paint.
- An attribute is extra configuration on a tag. Headings run from h1 through h6.
- Side-by-side boxes come from CSS, such as flexbox's initial row, not from a heading tag.
How does HTML run in a browser? The browser downloads the file, parses the bytes into a tree, applies CSS, and paints boxes. The HTML itself is the markup, not an executable program.
The HTML Standard says the input to parsing is a stream of code points. That stream passes through tokenization and then tree construction. The output is a Document.
In the common case the data comes from the network. It can also come from script, for example document.write().
An older W3C HTML5 copy describes the same handoff. Its tree-construction section says the input is a sequence of tokens and the output is dynamically modifying or extending the document’s DOM tree. Current rules live in the Living Standard.
The older text is useful as a map, not as a second competing standard to implement by hand.
What has to happen before the bytes arrive?
The browser has to find the server and open a connection. MDN’s guide to how browsers work starts with navigation, then a request whose response is headers plus HTML.
MDN says the first chunk of that HTML is usually 14KB, and parsing can start before the rest arrives. That figure is MDN’s, not a time this page measured.
You need a URL the browser can request, an HTML document, and, for a styled page, CSS. A local file can skip the network lookup. The parse steps below are the same idea once bytes are in hand.
What the markup is for, before any of this network detail, is the subject of the HTML guide.
How does the parser build the document?
It tokenizes the stream, then builds the tree. A token is emitted and handled immediately. The tree is the document scripts will see.
The Living Standard says the tokenizer acts as a state machine that starts in the data state. Tokens are DOCTYPE, start tag, end tag, comment, character, and end-of-file. Start and end tag tokens carry a tag name and attributes.
A token can be created and then abandoned if the file ends in the middle of a tag. Creating a token and emitting it are different steps.
Tree construction can pause the story. The standard says the tree stage is reentrant: while it handles one token, the tokenizer may resume. Its example is a script whose end tag causes document.write of a p start tag, so a paragraph token is handled before the script end tag finishes.
Parsers track a script nesting level and a parser pause flag for those cases.
MDN compresses the same idea for performance readers. HTML parsing is tokenization and tree construction. Tokens include start and end tags and attribute names and values.
The DOM tree describes the content. The html element is the root. Nested elements are child nodes.
More nodes mean more tree to build. Images can be fetched without stopping the parser. A classic script without async or defer can pause HTML parsing.
MDN also describes a preload scanner that looks ahead for CSS, scripts, and fonts so those requests start before the main parser reaches the tag. async on a script keeps that script from blocking. defer is the alternative when order matters.
How to add attributes in HTML?
Write them on the start tag. They configure the element. The parser stores them on the start tag token.
MDN’s attribute reference says an attribute is an additional value that configures the element or adjusts its behavior. href on an a is the URL of the linked resource. alt on an img is the text if the image cannot be displayed.
id must be unique. class marks elements that share styling.
The content attribute is what you wrote in the file. From script, getAttribute and setAttribute read and write it, and the value is a string. MDN’s example sets an input’s maxlength to 42 by calling setAttribute("maxlength", "42").
The matching JavaScript property, maxLength, is a number. That split is the attribute versus the property, and it matters once the tree exists.
Boolean attributes are true when present and false when absent. MDN says the values true and false are not the way to flip them. checked="false" still checks the control because the attribute is present.
Omit checked when the box should start unchecked.
Google’s supported meta tags page says meta tags are additional information for search engines and other clients, placed in the head. Clients ignore tags they do not support. A meta element is metadata in the HTML sense: it sets up the document rather than showing a paragraph.
The viewport meta is the one that page says tells the browser how to render the page on a mobile device.
How to write an HTML heading?
Use h1 through h6 for section titles. Do not pick a level because you want bigger type.
MDN’s heading page says these six elements are section headings, with h1 highest and h6 lowest. By default they are block boxes: a new line and the full width of the containing block. The technical summary lists their content categories as flow, heading, and palpable, with phrasing content inside.
MDN’s usage notes say heading information can feed a table of contents, that you should not skip levels, and that you should not use headings to resize text. Screen reader users often jump by heading. A jump from h1 to h3 leaves a gap.
Prefer h1, then h2, then h3. When a subsection ends, the next heading may return to a higher level. That return is not a skip in the same way.
A span is not a heading. It is phrasing content for a stretch of text inside a paragraph. The span guide covers that element.
How to make HTML elements side by side?
Use CSS on the parent. HTML’s headings and paragraphs stack as blocks until a layout mode says otherwise.
MDN’s flexbox guide says display: flex makes the direct children flex items. The initial flex-direction is row, so those items line up in a row. That is the side-by-side layout.
flex-wrap starts as nowrap. Set wrap if the row should break.
You need a parent, the children that should share the row, and a CSS rule the page loads. Putting two h2 elements next to each other in the file does not place them side by side. They are headings.
The flex container is what changes the layout.
What happens after the tree exists?
MDN names five steps in the critical rendering path: build the DOM, build the CSSOM, combine them into a render tree, run layout, then paint. Compositing can follow when layers overlap.
The CSSOM is a separate tree of computed styles, including the user agent’s rules. The render tree keeps visible nodes. MDN says display: none, including the usual treatment of script, leaves a node out of that tree.
visibility: hidden stays in, because the box still takes space.
Layout finds each box’s size and position. Paint turns those boxes into pixels on the screen, including text, colors, borders, and images.
A link in the head is how a page points at a favicon file. A favicon generator makes that file in the browser. The link is metadata.
The parser records it. The image request is a separate fetch, like any other linked resource.
| Step | What the sources say | A common miss |
|---|---|---|
| Fetch | DNS, TCP, TLS, then an HTTP GET for the HTML | A blocked request, so no bytes to parse |
| Tokenize | State machine emits tags, attributes, and text | A truncated tag that never becomes a token |
| Tree | Tokens build the Document | A parser-blocking script with no async or defer |
| Style and layout | CSSOM plus DOM, then box geometry | An image with no reserved size, so a later reflow |
| Paint | Boxes become pixels | Expecting a single millisecond figure for every page |
Read the pipeline in that order when a page is blank or late. The bytes, the tree, and the paint are three different stages. A timing number belongs to the source that measured it.
This guide does not add one.
Frequently asked questions
Does the browser wait for the whole file before parsing?
MDN's how-browsers-work guide says parsing can start with the first chunk, even when the HTML is larger than that chunk. It says the first chunk of content is usually 14KB, and that the browser tries to render from the data it already has. Linked resources are requested when the parser encounters them, and a preload scanner can request CSS, scripts, and images earlier. A script without async or defer can block parsing. Those notes describe the pipeline, not a fixed paint time for every page.
What are the tokens the parser emits?
The HTML Living Standard says tokenization emits zero or more of these tokens: DOCTYPE, start tag, end tag, comment, character, and end-of-file. A start tag token has a tag name, a self-closing flag, and a list of attributes, each with a name and a value. The tokenizer starts in the data state. When a token is emitted, tree construction handles it immediately. Tree construction can resume the tokenizer, which is how a script that writes more markup gets parsed in the middle of the document.
How do you add attributes in HTML?
Put them in the start tag as a name and a value. MDN's attribute reference says attributes are additional values that configure an element or adjust its behavior. A content attribute is always a string when you read it from script with getAttribute. Boolean attributes are true when they are present. Writing checked equals false does not uncheck the box, because the attribute is still there. To represent false, omit the attribute. Global attributes such as id and class can sit on any element.
How do you write an HTML heading?
Use h1 through h6. MDN says h1 is the highest section level and h6 is the lowest. Both the start tag and the end tag are required. Headings are heading content, flow content, and palpable content, and they contain phrasing content. Do not skip levels, and do not use a heading just to enlarge text. Use CSS font-size for size. MDN says multiple h1 elements are allowed if they are not nested, and it prefers one h1 for the page.
Why did the layout jump after an image loaded?
MDN's rendering guide says layout computes each node's size and position. If an image arrives without reserved dimensions, a later layout, called a reflow, runs once the size is known. Paint then runs again. Reserving width and height on the image, or sizing the box in CSS, gives the first layout a box to keep. That is a layout fact from MDN, not a claim about a universal number of milliseconds.
Sources
- HTML Standard: Parsing · WHATWG, 2026
- Populating the page: how browsers work · MDN, 2026
- HTML attribute reference · MDN, 2026
- Heading elements · MDN, 2026
- Basic concepts of flexbox · MDN, 2026
- Meta tags and attributes that Google supports · Google Search Central, 2026
- 8.2.5 Tree construction · W3C HTML5, 2026