The Critical Rendering Path
Build an accurate mental model of what the browser does, from navigation and HTTP through parsing, rendering, storage, workers, security, and DevTools, so you can predict behavior and debug real pages.
What you will be able to do
#- Order the steps from HTML bytes to first paint.
- Identify resources that delay the first paint.
- Use preconnect, preload, and prefetch correctly.
Overview
#The critical rendering path is the sequence from HTML bytes to the first painted pixels.
The sequence
HTML arrives, the DOM is built, CSS is fetched and parsed into the CSSOM, the render tree is built, layout runs, and the first frame is painted. First Contentful Paint (FCP) measures the first paint that renders content such as text or an image; a background-only First Paint (FP) can occur slightly earlier.
Blocking resources
Render-blocking CSS and parser-blocking scripts delay the first paint. Inline critical CSS in the head and defer non-critical CSS with media or onload. Load scripts with defer or async.
Hints
preconnectwarms a connection to a critical origin.preloadfetches a resource needed soon, such as a font or hero image.prefetchfetches a resource likely needed later.
Largest Contentful Paint
LCP is the render time of the largest image or text block in the viewport. Optimize the LCP resource first: preload it, serve it in a modern format, and avoid lazy-loading it.
Questions to carry forward
- What is the difference between preload and prefetch?
- Why can lazy-loading hurt LCP?
- How do you inline critical CSS safely?
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Debug
A hero image is the LCP element but has loading="lazy". Why is LCP bad and what do you change?
starter.html<img src="hero.jpg" loading="lazy" alt="hero">Reveal the reference answer
reference.html<img src="hero.jpg" loading="eager" fetchpriority="high" alt="hero">Authored expected output: The hero loads early instead of waiting for the viewport heuristic.
loading=lazy defers the request until layout decides the image is near the viewport, which delays LCP. The LCP image should load eagerly with high priority, and can be preloaded.
Exercise 2Predict
Which hint should you use for a font needed for the first paint?
Common misconceptions
#- preload and prefetch are interchangeable.
- Lazy-loading the hero image improves LCP.
- FCP and LCP measure the same element.
Follow-up practice
#- browser-internals-devtools-performance
- browser-internals-core-web-vitals
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.