A browser reads an HTML document from the top and acts on each line as it
arrives, which is why the order of the head decides how fast anything appears. A<script src> with no attribute stops the parser dead: the file
is fetched and executed before the next tag is read, and nothing after it exists
yet, including the thing the script is probably looking for.
Two attributes fix it and they are not the same.defer downloads in parallel and runs after the document is parsed,
in the order the scripts appear. async downloads in parallel and
runs the moment it arrives, in whatever order that turns out to be. Usedefer for anything that touches the page and async
only for something genuinely independent, such as an analytics beacon.
What the head is actually for
<meta charset="utf-8">first, within the first kilobyte,
because until it is read the browser is guessing the encoding of everything
before it<title>, which is the tab, the bookmark, the search
result and the first thing a screen reader announces on page load<meta name="viewport" content="width=device-width, initial-scale=1">,
without which a phone renders the page at desktop width and scales it down<link rel="stylesheet">, which blocks rendering but not
parsing, and that is deliberate: the alternative is showing unstyled text and
then repainting
The lang attribute on <html> belongs in the
same list and is left off more often than any of them. It decides which voice a
screen reader uses, how hyphenation works, and which font a browser reaches for,
and it is one attribute.
One page, top to bottom
What the browser does with each line as it arrives
Every stop here happens before the next line of the file is read, which is why the position of one tag changes when anything appears.
- charset is readUntil this line, the encoding of everything above it was a guess
- title and viewportThe tab is named, and a phone stops rendering at desktop width
- The stylesheet is fetchedRendering waits, parsing does not. That trade is deliberate
- A bare script tagEverything stops until it has downloaded and run
- The body is parsedThe tree is built, and mis-nesting is silently repaired here
- Deferred scripts runIn source order, with the whole document available to them
An async script has no place on this rail: it runs whenever it arrives, which may be between any two of these stops or after all of them.
Interactive Practice Lab
Edit and run this snippet directly in your browser (zero setup)
<article style="padding:14px;border:1px solid color-mix(in srgb,currentColor 24%,transparent);border-radius:12px"> <h3 style="margin:0 0 6px">Semantic Card</h3> <p style="margin:0 0 10px;opacity:.85">Edit this HTML and click Run to preview live.</p> <button onclick="console.log('Button clicked at', new Date().toLocaleTimeString())">Test Event</button></article>Live Big-O Complexity & Binary Search Race Lab
Compare complexity curves at scale and watch Linear vs Binary Search race live.
The tree the browser builds is not the file you wrote
HTML parsing is error tolerant by specification, so a missing closing tag
does not fail, it produces a different tree. A <p> containing
a <div> is closed early by the parser, because a p cannot
contain a div, and the result is two paragraphs and a div where you wrote one
paragraph. Nothing reports it.
Silent HTML repair
The tree the browser builds is not always the file you wrote
Because HTML parsing is error tolerant, invalid nesting or missing end tags never fail to compile and instead produce a restructured DOM.
When styles refuse to apply to an element, inspect the live DOM tree before rewriting CSS.
Which is why the validator matters more here than in a language that refuses
to compile. The rule to carry: when CSS does not apply to the element you think
it does, look at the tree in the inspector before touching the stylesheet,
because the element may not be where the file says it is. What that tree is and
how it is read from script is
reading and changing the
page from script.
What to run in 2026
The W3C HTML validator is the tool, free, and it is the only thing that
reports the mis-nesting above. Run it once per template rather than per page,
because the faults are almost always in the layout rather than in the content.
It replaced reading the markup for balance, which the parser does not do
either.
Verification tools in 2026
Checking document structure and spotting blocking scripts
Two free tools catch the two things reading raw HTML misses: silent tag repair and parser stalls.
- W3C HTML validatorOnly tool that reports silent mis-nesting
- Run once per shared layout template
- Catches invalid nesting like div inside p
- Replaces manual tag-balance checks
- Browser performance panelShows exactly when HTML parsing stalled
- Read the parse track on the timeline
- Spot blank render gaps matching script downloads
- Replaces guessing by moving script tags
Validating shared templates once catches structural faults across every page built from them.
The browser's performance panel is the second, free in every browser, and the
part to look at is the row showing when parsing stopped. A blocking script shows
as a gap with nothing rendered, and the gap is exactly as long as the download.
It replaced moving script tags around and guessing whether it helped.
Where this stalls people
The stall is putting scripts at the end of the body because a tutorial said
so, and then never learning why. That advice was correct beforedefer was universal, and it has one cost that still bites: a script
at the end of the body is discovered late, so its download does not start until
the parser reaches it.
Early discovery vs late discovery
Why defer in the head beats scripts at the end of the body
Putting scripts at the bottom avoids blocking head parsing, yet delays when the browser even learns the file needs to be downloaded.
- At the end of bodyDiscovered only after HTML finishesDownload cannot begin until the parser reaches the bottom of the document
- Old pre-defer workaround
- Delays network fetch on slow links
- Script arrives after parsing instead of during it
- In head with deferFetched early, executed after parseBrowser downloads the file in parallel right away while waiting for the full DOM
- Discovery starts on initial head read
- Parsing continues uninterrupted
- Scripts still run in source order
Use async only for independent scripts like analytics beacons that never depend on the DOM or other scripts.
defer in the head is strictly better, because the download
starts immediately and the execution still waits for the document. The reason
this matters is that it is the difference between a script that arrives during
parsing and one that arrives after it, on a slow connection. Which elements the
parser is building is
elements that say what they are,
and who that helps, what all of this does to the page's speed is
why a page feels slow, and what
actually fixes it, and it all sits inside
the structure under every page.