Improving Google Lighthouse Scores: Core Web Vitals (LCP, CLS, INP)
Improving Google Lighthouse Scores: Core Web Vitals (LCP, CLS, INP)
Imagine entering a bank to deposit cash. If the main entrance glass door is stuck and takes 10 seconds to open (LCP), you get frustrated. Once inside, if the deposit slip countertop suddenly jumps two feet to the left right as your pen touches the paper (CLS), you scribble an accidental error on your cheque. And when you finally click the service bell and wait 5 seconds before anyone even looks up (INP), you leave with a terrible impression.
In 2020, Google officially made Core Web Vitals an organic search engine ranking signal. If your website scores poorly on Google Lighthouse, your search rankings plunge and bounce rates skyrocket. While many developers assume performance is purely a backend or JavaScript issue, over 60% of Core Web Vitals penalties are directly caused by unoptimized CSS and font-loading patterns!
1. The Big 3 Core Web Vitals Explained
+-------------------------------------------------------------------------+
| THE 3 GOOGLE CORE WEB VITALS BENCHMARKS |
+-------------------------------------------------------------------------+
1. LCP (Largest Contentful Paint) Target: <= 2.5 seconds
Measures PERCEIVED LOADING SPEED.
When does the largest headline or hero banner image finish painting?
2. CLS (Cumulative Layout Shift) Target: <= 0.1
Measures VISUAL STABILITY.
Do buttons, banners, or paragraphs jump around as fonts and images load?
3. INP (Interaction to Next Paint) Target: <= 200 milliseconds
Measures USER INTERACTION RESPONSIVENESS.
When the user clicks a tab or menu, does the UI respond immediately?2. Eliminating Font Layout Shift with font-display & size-adjust
When a custom Google Font (like Inter or Poppins) is loading, two disasters commonly occur:
- FOIT (Flash of Invisible Text): The browser hides text completely for up to 3 seconds until the font file arrives.
- FOUT (Flash of Unstyled Text): The browser shows Arial first, and when Poppins arrives, the text size differences cause the entire article to jump, racking up heavy CLS penalties!
The Modern Font Solution:
When the custom font finishes downloading, zero pixels shift on screen because the fallback font was mathematically calibrated to match its exact footprint!
3. Fixing Largest Contentful Paint (LCP) via CSS
The LCP element on most websites is either a large hero headline or a background hero image.
CSS Techniques to Accelerate LCP:
- 1Preload the Hero Font:
- 1Never Lazy-Load the LCP Image:
- 1Avoid Background Images for LCP Elements: The browser discovers
<img>tags in HTML immediately via the Preload Scanner. However, an image declared via CSSbackground-image: url('hero.jpg')cannot be discovered until the CSS file is completely downloaded and parsed!
4. Conquering CLS: Aspect Ratio Reservation
Cumulative Layout Shift happens when elements render with zero initial height and suddenly pop open.
5. Do's and Don'ts of Core Web Vitals Optimization
| Category | Do | Don't |
|---|---|---|
| Font Display | Always set font-display: swap on @font-face declarations. | Allow text to remain completely invisible for seconds (FOIT). |
| Image Reservation | Use aspect-ratio: 16 / 9 or explicit width and height attributes on images. | Insert naked <img> tags with zero dimensional constraints, destroying CLS. |
| Hero Graphics | Use standard <img> with fetchpriority="high" for hero banners. | Use CSS background-image for LCP heroes, hiding the asset from the HTML preload scanner. |
| Animations | Animate exclusively using transform and opacity. | Animate top, left, width, or height, which triggers continuous layout recalculations and hurts INP. |
6. Quick Revision Summary
+-------------------------------------------------------------------------+
| CORE WEB VITALS OPTIMIZATION CHEAT SHEET |
+-------------------------------------------------------------------------+
1. LCP <= 2.5s:
- Inline Critical CSS (<14KB).
- Preload .woff2 fonts with crossorigin.
- Use <img> with fetchpriority="high" for hero artwork.
2. CLS <= 0.1:
- img { aspect-ratio: 16/9; }
- Reserve ad & widget container min-heights.
- Calibrate fallback fonts with size-adjust.
3. INP <= 200ms:
- Animate with transform & opacity only.
- Keep CSS selector specificity flat (BEM / @layer).Multiple Choice Questions
1. Which Google Core Web Vital metric measures the visual stability of a webpage to prevent unexpected layout jumping?
A. First Input Delay (FID) B. Cumulative Layout Shift (CLS) C. Time to First Byte (TTFB) D. Total Blocking Time (TBT)
2. What does declaring font-display: swap; inside an @font-face block achieve?
A. It disables italic font variants B. It instructs the browser to render text immediately using a fallback system font, then swap in the web font once it finishes loading, eliminating invisible text (FOIT) C. It converts web fonts into SVG outlines D. It rotates fonts upside down
font-display: swap instructs the browser to immediately display fallback system text rather than waiting in the dark with blank invisible text (FOIT), ensuring immediate readability.3. Why does declaring a hero banner image as an HTML <img> with fetchpriority="high" outperform a CSS background-image for LCP?
A. HTML tags are scanned and preloaded by the browser's fast C++ Preload Scanner before CSS files finish parsing B. CSS images cannot display high-resolution colors C. Background images are disabled on 4G networks D. fetchpriority only works inside JavaScript
<img> tags while downloading the HTML stream. CSS background-image references remain completely invisible to the browser until the entire stylesheet has downloaded and parsed.4. How does size-adjust inside @font-face help eliminate Cumulative Layout Shift (CLS)?
A. It compresses the font file size B. It scales the glyph dimensions of the fallback system font so its physical footprint matches the incoming web font, preventing text reflow during font swap C. It automatically translates text into different languages D. It forces text to fit inside a single line
size-adjust scales fallback system fonts (like Arial) to match the exact physical proportions of custom web fonts (like Poppins), eliminating the layout jump when fonts swap.5. To maintain responsive Interaction to Next Paint (INP <= 200ms), which CSS properties should be used for UI transitions and hover animations?
A. width and height B. transform and opacity C. margin-top and padding-left D. top and left
transform and opacity are executed on the GPU compositor thread without triggering layout reflows or repaints on the main thread, keeping the main thread free to respond to user interactions instantly.Hands-On Practice Challenge: Google Lighthouse Core Web Vitals Studio
Experiment with this interactive performance telemetry station. Toggle image aspect ratio reservation and font display swap to watch the simulated Lighthouse Performance Score leap to 100!
Project 1: Interactive Analytics Dashboard UI with Grid & Container Queries
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.