Skip to content
Tech Interview Prep
Technical interview guide

DOM and Browser Rendering

How the browser turns HTML, CSS and JavaScript into pixels: the critical rendering path, style/layout/paint/composite, what reflow and repaint actually cost, event propagation, and semantic HTML. These decide both whether a page is correct and how fast it feels.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v2
Editorial status
Reviewed

Scope: Current to the WHATWG HTML Living Standard and the CSSOM/Event specs; rendering-pipeline behaviour described is Chromium's as documented on web.dev and chromium.org, with Gecko and WebKit differences called out where they change the answer. Checked against Chrome 131, Firefox 133, Safari 18..

Overview

Curated: · Written: · Reviewed:

DOM and Browser Rendering

In one line

The browser turns HTML into pixels through parse, style, layout, paint and composite. A DOM or CSS change re-enters at the earliest stage it touches, so name that stage when a page paints late, stutters or responds slowly.

Key definitions

  • Render-blocking stylesheet: a <link rel=stylesheet> whose media query matches the viewport. Paint waits for its CSSOM, and it also holds back any classic script after it.
  • Parser-blocking script: a classic <script> with neither defer nor async. The parser stops until it is fetched and executed.
  • Render tree: the boxes that get laid out and painted. It omits head, script and display: none subtrees and includes ::before and ::after boxes.
  • Forced synchronous layout: a geometry read after a style write, which flushes pending style and layout inside the current task.
  • Event phases: capture runs from window down to the target, the target is where the event fires, and bubble runs back up.
  • Accessibility tree: built from the DOM, filtered and augmented by ARIA. Assistive technology reads this tree, not the markup.

Formulas and complexity

frame budget at 60 Hz=1000 ms60≈16.7 ms\text{frame budget at 60 Hz} = \frac{1000\ \text{ms}}{60} \approx 16.7\ \text{ms} layer memory=w×h×DPR2×4 bytes\text{layer memory} = w \times h \times \text{DPR}^2 \times 4\ \text{bytes} long task>50 ms\text{long task} > 50\ \text{ms}

Hypothetical: a 1000 by 1000 CSS px layer at DPR 2 is 2000 by 2000 device px, about 16 MB. Ten such layers hold about 160 MB.

How it works

  • A classic script halts the parser. The preload scanner keeps fetching images, stylesheets and later scripts ahead of it.
  • Before first paint, every matching stylesheet must produce a CSSOM.
  • Style, layout, paint and composite run in that order. A change re-enters at the earliest stage it touches.
  • transform and opacity on a composited layer skip style, layout and paint, so only composite runs.
HTML bytes Parse to DOM Parse CSS to CSSOM Style Layout Paint Composite

When to use and when not to

TechniqueUse whenCost
Animate transform or opacityMotion on an element that is already composited, or easily promotedOne GPU layer per promoted element
Animate top, left, widthNever for motionLayout and paint on every frame
deferScript needs the DOM and execution order mattersRuns after parse, before DOMContentLoaded
asyncScript is independent (analytics, polyfill loader)Execution order is not guaranteed
content-visibility: autoLong sections far below the foldSkipped sections have no size until contain-intrinsic-size gives one, so page height shifts as the reader scrolls
will-changeMeasured jank on a known layerMemory held whether or not the animation runs
Inline critical CSSFirst screen needs only a small stylesheetRepeated in every HTML document and not cached separately

Traps interviewers probe

  • Stylesheets never block rendering. Matching ones do, and they also delay classic scripts after them. Fix: scope media queries correctly and keep the critical stylesheet small.
  • visibility: hidden removes an element. It keeps its space and stays in the accessibility tree and the tab order. Fix: use display: none or inert when the element must leave both.
  • Reading offsetHeight is free. It flushes pending layout. Fix: read all values first, write all values second, or schedule writes in requestAnimationFrame.
  • Delegation catches every event. focus, blur, mouseenter and mouseleave do not bubble. Fix: use focusin, focusout, mouseover or mouseout, or listen in the capture phase.
  • preventDefault() in a document-level touch or wheel listener works. Chrome treats those listeners as passive by default, so the call is ignored and a console warning is logged. Fix: pass { passive: false } explicitly, or attach the listener to the element that needs it.

Interview tips

Open by naming the stage a change forces: "This writes top every frame, so each frame reruns layout and paint. transform skips both." Then give the cost and the trace that shows it.

Expect these follow-ups:

  • Why defer over async for an app bundle that touches the DOM?
  • Why does a stylesheet above a script delay that script?
  • How do you confirm forced layout in a trace? Look for Layout blocks inside long tasks, change the property, and record again.
  • How do you attribute a 480 ms INP? INP above 200 ms needs work and above 500 ms is poor. Find the long task in the event timing entries, then check which handler and which forced layout sit inside it.

30-second outline: "Parsing stops at a classic script, and a matching stylesheet must reach the CSSOM before first paint. Changes re-enter at the earliest stage they touch. Animating transform on a composited layer skips layout and paint, but each layer costs GPU memory. I would confirm the stage in a Performance trace before changing anything."

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.