Astro Core Web Vitals start in a good place because Astro sends complete HTML and no client JavaScript unless you opt in. To keep them green, fix three things in order: give the largest above-the-fold image priority and real dimensions (LCP), keep hydrated islands and third-party scripts off the critical path (INP), and reserve space for every image, font swap and embed (CLS).
The rest of this guide shows what each metric measures, which Astro features affect it, and how to measure real users instead of guessing from one Lighthouse run.
Key Takeaways
- Google’s “good” thresholds, at the 75th percentile of real visits: LCP 2.5 s or less, INP 200 ms or less, CLS 0.1 or less.
- On most Astro sites, LCP is an image problem. Use
<Image priority />on the hero and nowhere else.- INP problems almost always come from JavaScript you added: eager
client:loadislands, tag managers, chat widgets.- CLS comes from missing image dimensions, late web fonts and injected banners. Astro’s
<Image>and Fonts API handle the first two.- Lab tools (Lighthouse) find problems; field data (CrUX, the
web-vitalslibrary) tells you whether users actually see them.
What Core Web Vitals measure
Core Web Vitals are three user-experience metrics Google uses as a page experience signal in Search and reports in Search Console. Each has a “good”, “needs improvement” and “poor” band, and a URL passes when 75% of real page loads land in “good”.
| Metric | What it measures | Good | Poor |
|---|---|---|---|
| LCP (Largest Contentful Paint) | When the biggest image or text block in the viewport renders | 2.5 s or less | Over 4 s |
| INP (Interaction to Next Paint) | Delay between a tap, click or key press and the next visual update | 200 ms or less | Over 500 ms |
| CLS (Cumulative Layout Shift) | How much visible content moves unexpectedly | 0.1 or less | Over 0.25 |
INP replaced First Input Delay as a Core Web Vital in March 2024. It is stricter, because it looks at every interaction on the page, not just the first one. The web.dev Core Web Vitals overview is the reference for the definitions.
Why Astro sites usually start green
Astro’s defaults line up with what the metrics reward:
- Server-rendered HTML. Text content is in the first response, so the largest text block can paint without waiting for a JavaScript bundle.
- Zero JavaScript by default. Components render to HTML at build time. Only components with a
client:*directive ship code to the browser, which leaves the main thread free for input. - Static output. A prerendered page served from a CDN has a short time to first byte, and every later metric starts from that number.
That is a head start, not a guarantee. A single 3 MB hero JPEG, a tag manager loading six vendors, or a cookie banner that pushes the page down will fail an Astro site as quickly as any other. The Astro performance guide covers the wider picture; this article focuses on the three metrics.
Fixing LCP in Astro
LCP is usually the hero image on landing pages and the headline on text pages. Find which element it is first: in Chrome DevTools, record a page load in the Performance panel and look for the LCP marker, or run Lighthouse and read the “Largest Contentful Paint element” audit.
Use Image with priority for the hero
---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import hero from '../assets/hero.jpg';
---
<section class="hero">
<Image
src={hero}
alt="Dashboard showing weekly revenue"
widths={[640, 960, 1280, 1920]}
sizes="100vw"
priority
/>
<h1>Ship your product site this week</h1>
</section>
priority tells Astro this image is above the fold, so it is loaded eagerly with high fetch priority instead of the default lazy loading. Use it on one image per page. Putting it on everything cancels the benefit, because the browser can no longer tell which request matters.
Importing the file (instead of pointing at public/) lets Astro convert it to WebP, generate the widths you list, and write width and height attributes. Shrinking an oversized hero is usually the single largest LCP improvement a site can make. See the Astro Image component guide for every prop.
Don’t hide the LCP element behind JavaScript
If the hero lives inside a React or Vue carousel with client:load, the image may not render until the framework hydrates. Render the first slide as plain Astro markup and only hydrate the controls, or replace the carousel with a CSS scroll-snap version that needs no JavaScript.
The same applies to fade-in animations. An element that starts at opacity: 0 and waits for a scroll library to reveal it delays LCP until the script runs.
Keep fonts from blocking text
When the LCP element is a heading, a late web font can hold back the paint. Astro’s Fonts API (stable since Astro 6) downloads the font at build time, serves it from your own domain and generates a size-adjusted fallback:
// astro.config.mjs
import { defineConfig, fontProviders } from 'astro/config';
export default defineConfig({
fonts: [
{
provider: fontProviders.google(),
name: 'Inter',
cssVariable: '--font-inter',
weights: [400, 700],
},
],
});
---
// src/layouts/BaseLayout.astro
import { Font } from 'astro:assets';
---
<head>
<Font cssVariable="--font-inter" preload />
</head>
Preload only the one or two weights used above the fold. Every preloaded file competes with the hero image for bandwidth.
Fixing INP in Astro
INP measures how quickly the page responds when someone interacts with it. A slow INP means the main thread was busy running JavaScript when the user tapped. On an Astro site that JavaScript is almost always something you chose to add, which makes it easier to find.
Audit your client directives
Search the project for hydrated components:
grep -rn "client:" src/
For each result, ask whether it needs to run on page load:
| Directive | When the component hydrates | Use for |
|---|---|---|
client:load |
Immediately | Controls needed in the first second, rare |
client:idle |
When the browser is idle | Non-urgent widgets near the top |
client:visible |
When it scrolls into view | Anything below the fold |
client:media="(max-width: 768px)" |
When the media query matches | Mobile-only menus |
client:only="react" |
On load, skips server render | Components that can’t render on the server |
Switching a below-the-fold newsletter form or comment widget from client:load to client:visible removes its hydration cost from page load entirely. The client directive decision guide walks through the choice per component.
Replace small islands with a script tag
A toggle, a tab set or a copy button doesn’t need a framework. A component-scoped <script> in an .astro file is bundled, deduplicated and deferred by Astro:
---
// src/components/MenuToggle.astro
---
<button aria-expanded="false" aria-controls="site-menu" data-menu-toggle>Menu</button>
<script>
// Runs once per page, after the HTML is parsed
const button = document.querySelector('[data-menu-toggle]');
const menu = document.getElementById('site-menu');
button?.addEventListener('click', () => {
const open = button.getAttribute('aria-expanded') === 'true';
button.setAttribute('aria-expanded', String(!open));
menu?.toggleAttribute('hidden', open);
});
</script>
That is a few hundred bytes instead of a framework runtime plus a hydration pass.
Move third-party scripts out of the way
Analytics, tag managers and chat widgets run long tasks on the main thread. Options, from best to worst: remove the script, load it after the first interaction, or move it into a web worker with Partytown. The Partytown guide for Astro covers the setup and the scripts it can’t handle.
Break up long handlers
If your own code does heavy work on click (filtering a large list, for example), yield to the browser before the expensive part so the visual feedback paints first:
// src/scripts/filter.ts
async function onFilterClick(button: HTMLButtonElement) {
button.classList.add('is-active'); // visual update first
await new Promise((r) => setTimeout(r, 0)); // let the browser paint
applyFilter(button.dataset.filter ?? ''); // then the slow work
}
Fixing CLS in Astro
CLS adds up every unexpected movement of visible content. The causes are predictable.
Images without dimensions
<Image> and <Picture> from astro:assets always output width and height, so the browser reserves the right box before the file arrives. Plain <img> tags in Markdown or in components pointing at public/ don’t, unless you add the attributes yourself. Astro’s responsive image layouts also add the styles that keep the aspect ratio when the image scales:
// astro.config.mjs
export default defineConfig({
image: {
layout: 'constrained',
responsiveStyles: true,
},
});
Fonts swapping metrics
A fallback font with different widths reflows every line when the web font arrives. The Fonts API’s generated fallback adjusts size-adjust, ascent-override and related metrics so the swap barely moves anything. If you self-host fonts manually, use font-display: swap with a metric-matched fallback, or optional if you’d rather skip the swap on slow connections.
Banners, embeds and ads
Cookie banners, announcement bars and iframes that insert themselves above content are the classic CLS failure. Either reserve their space in the initial HTML (a fixed-height container), or position them as overlays with position: fixed so they don’t push the page. For embeds, set an aspect-ratio on the wrapper:
/* src/styles/global.css */
.video-embed {
aspect-ratio: 16 / 9;
width: 100%;
}
View transitions
With <ClientRouter />, navigations swap the page without a full reload. Layout shifts during the swap are not counted the same way as on a fresh load, but content that loads in after the swap still is. Keep the same rules for images and fonts on every page, not just the first one.
Measuring Core Web Vitals on an Astro site
Use two kinds of data, for different jobs.
Lab data comes from a single controlled run: Lighthouse in Chrome DevTools, PageSpeed Insights’ lab section, or npx astro build followed by npx astro preview and a local audit. It is repeatable, so it is the right tool for checking whether a fix worked. It can’t measure INP directly, because there’s no real user interacting; it reports Total Blocking Time as a proxy.
Field data comes from real visitors. PageSpeed Insights shows Chrome User Experience Report (CrUX) data when a URL has enough traffic, and Search Console groups URLs by status. For your own real-user monitoring, add the web-vitals library:
---
// src/components/WebVitals.astro
---
<script>
import { onCLS, onINP, onLCP } from 'web-vitals';
function send(metric: { name: string; value: number; id: string }) {
navigator.sendBeacon('/api/vitals', JSON.stringify(metric));
}
onCLS(send);
onINP(send);
onLCP(send);
</script>
Astro bundles the import like any other script. Send the data to your analytics tool, or to an endpoint if your site has on-demand rendering. On a fully static site, many privacy-friendly analytics services accept custom events directly.
Run lab tests on the production build, never on astro dev. The dev server serves unbundled modules and unoptimized images, so its numbers say nothing about the deployed site.
A Core Web Vitals checklist for Astro
- Find the LCP element on your three most important templates.
- Make the hero an imported image rendered with
<Image>or<Picture>andpriority. - Move fonts to the Fonts API and preload only above-the-fold weights.
- List every
client:*directive and downgrade anything that isn’t needed on load. - Replace small framework islands with component
<script>tags. - Remove, delay or move third-party scripts to Partytown.
- Give every image, iframe and banner reserved space.
- Check field data in Search Console 28 days after the change, since CrUX is a rolling window.
If you’d rather start from a site that already follows these rules, every Komal theme is a static Astro 7 project with no client JavaScript unless a component needs it. You can browse Astro themes and open any live preview to run your own audit first. For configuration options mentioned here, see the Astro config docs.
FAQ
Does Astro improve Core Web Vitals automatically?
Partly. Astro’s server-rendered HTML and zero-JavaScript default give good LCP and INP starting points, and <Image> prevents image layout shift. It can’t fix a heavy hero file you reference from public/, scripts you add to the head, or banners that push content down.
Why is my Astro site’s INP poor when it ships little JavaScript?
Check third-party scripts first. Tag managers, chat widgets and A/B testing tools run long tasks on the main thread regardless of the framework. After that, look for islands hydrated with client:load that could use client:visible or client:idle.
How long does it take for Core Web Vitals to update in Search Console?
Search Console uses CrUX field data collected over a rolling 28-day window, so a fix shows fully about four weeks after it reaches real users. Use PageSpeed Insights lab data or Lighthouse to confirm the fix immediately.
Should I use priority on every image in Astro?
No. Use priority on the single image most likely to be the LCP element, usually the hero. Every other image should stay lazy-loaded so it doesn’t compete for bandwidth during the first paint.
Do Core Web Vitals affect rankings?
Google uses Core Web Vitals as part of its page experience signals. They matter most as a tiebreaker between pages of similar relevance, and they directly affect bounce rates and conversions, which is reason enough to fix them.