BYTESLIP ← Back
Knowledge Base // Tutorial 117

Fix LCP, INP and CLS on a Plain HTML Site: Measured Before and After

Difficulty: Medium ~45 min HTML · Core Web Vitals

A static site starts fast, then a lazy-loaded hero image, a banner that pops in, or one heavy click handler drags it into the red. Google’s targets are LCP within 2.5 s, INP under 200 ms and CLS under 0.1. This guide fixes each one with a few lines of HTML or JavaScript. We measured the same demo page before and after: LCP dropped from about 2.36 s to 1.17 s, CLS from 0.087 to 0, and the slow click from 320 ms to 24 ms.

Core Web Vitals fix order Four tiles: measure, LCP hero image, CLS reserve space, INP yield. MEASURE LCP HERO IMAGE CLS RESERVE SPACE INP YIELD
Safety // Read First

Warnings

ImportantLab numbers are not what Google uses. Search Console and the top of PageSpeed Insights show field data from real Chrome users, and web.dev says to work from that first. A low-traffic page may have no field data at all. Then use the lab section as a guide, but don’t expect the field numbers to move right away.

Checklist // Before You Start

What You Need

How this was tested: We served two copies of a demo page from Apache 2.4.71 on Linux and loaded each three times in headless Chrome. Settings: 390 px phone viewport, 3× pixel density, 1.6 Mbps with 150 ms latency, and 4× CPU slowdown. We read LCP, layout shifts and event timing with the browser’s PerformanceObserver API. All three runs agreed: LCP 2.35–2.36 s → 1.16–1.18 s, CLS 0.087 → 0, and the tap from 320 ms → 16–24 ms. These are lab numbers for one page, so your own will differ.

Walkthrough // Steps 01–05

Measure → LCP → CLS → INP → re-measure

Fix the metric that’s failing first. Each step is independent.

  1. Step 1: Find out which metric is actually failing

    Open PageSpeed Insights, paste your URL, and read the top section, “Discover what your real users are experiencing”. If a URL doesn’t have enough data, PageSpeed Insights shows data for your whole site (origin) instead. The bottom section, “Diagnose performance issues”, is a lab run. It names your LCP element and lists layout shifts.

    Google’s thresholds: LCP ≤ 2.5 s, INP ≤ 200 ms, CLS ≤ 0.1, measured at the 75th percentile of page visits.

  2. Step 2: LCP: load the hero image early and small

    On most article pages, the LCP element is the hero image. web.dev’s rules: the browser has to find it in the HTML (not a CSS background added later), and you should never lazy-load your LCP image. Add fetchpriority="high" to that one image only. web.dev warns that giving more than one or two images high priority stops helping.

    Before:

    <img src="lava-1440.jpg" alt="Molten lava in a skylight" loading="lazy">
    <div id="banner-slot"></div>  <!-- a script drops a 90px banner here later -->

    After (sizes also fix CLS, see next step):

    <img src="lava-960.avif" alt="Molten lava in a skylight"
         width="1440" height="960" fetchpriority="high" decoding="async">
    <div id="banner-slot" style="min-height:90px"></div>

    In our test, the AVIF version at 960 px was 72 KB, compared with 382 KB for the 1440 px JPEG. Together with the eager, high-priority load, LCP went from about 2.36 s to 1.17 s.

  3. Step 3: CLS: give every image and late element its space

    web.dev lists the top causes: images without dimensions, embeds and iframes without dimensions, content injected later, and web fonts.

    • Images: always add width and height attributes, using the file’s real pixel size. With max-width:100%;height:auto in your CSS, the browser keeps the right aspect ratio at any screen width.
    • Late content (banners, embeds, “new post” notices): reserve its space with min-height or aspect-ratio on the container, as in the banner-slot line above.
    • Fonts: always list a fallback, like font-family: Inter, sans-serif, and preload the one font file used above the fold with <link rel="preload" as="font" type="font/woff2" crossorigin>. Another option is font-display: optional.

    In the demo, the image without dimensions and the late banner added up to CLS 0.087. With dimensions and a reserved slot, it was 0 in all three runs.

  4. Step 4: INP: paint feedback first, then do the heavy work

    INP measures how long the page takes to paint after a tap. If a handler does 300 ms of work before it returns, nothing can paint until it’s done. web.dev’s fix is to break up the work: setTimeout runs its callback in a new task, so the browser paints in between.

    Before (320 ms in our test):

    button.addEventListener('click', () => {
      doHeavyWork();                 // 300 ms of work before anything paints
      out.textContent = 'Done';
    });

    After (16–24 ms):

    button.addEventListener('click', () => {
      out.textContent = 'Working…';  // 1. show feedback right away
      setTimeout(() => {             // 2. run the heavy part in a new task
        doHeavyWork();
        out.textContent = 'Done';
      }, 0);
    });

    The work still takes the same time, but the reader sees a response right away. On a plain HTML site, it’s also worth checking third-party widgets and analytics scripts, which are the usual sources of slow handlers.

  5. Step 5: Re-measure and give the field data time

    Run PageSpeed Insights again after you upload. The lab section updates right away. The real-user section and Search Console’s Core Web Vitals report update slowly, because they’re built from many real visits. Before you look again, finish the page-level fixes that apply to every page built from the same template, like the header image, fonts and scripts.

Pro Tip

Fix the template, not the page

Questions // FAQ

FAQ

Are Core Web Vitals a ranking factor?

Google says it highly recommends good Core Web Vitals for success with Search, and that they align with what its core ranking systems reward. Relevance and helpful content still come first.

Why is my Lighthouse score green but Search Console red?

Lighthouse is one lab load. Search Console uses real visits across devices and networks, and CLS in the field includes shifts after load, like ones that happen while scrolling.

Should I lazy-load all images?

Only the ones below the fold. Lazy-loading the hero image delays LCP. Keep width and height on lazy images too, so they don’t shift the layout when they arrive.

What replaced FID?

INP replaced First Input Delay as a Core Web Vital in March 2024. It looks at the page’s interactions over the whole visit, not just the first one.

Keep Reading
Sources // Verified

Official docs

Thresholds and Search guidance: Understanding Core Web Vitals and Google search results. LCP subparts, lazy-loading warning, fetchpriority, and field versus lab data: Optimize Largest Contentful Paint. CLS causes, dimensions, reserving space, and fonts: Optimize Cumulative Layout Shift. Breaking up long tasks with setTimeout: Optimize Interaction to Next Paint. Dimensions on lazy images: Browser-level image lazy loading. INP replacing FID: Introducing INP to Core Web Vitals.

← All Tutorials Byteslip Apps