To prioritize the LCP image in Astro, add the priority prop to the hero’s <Image> or <Picture> component. Astro then renders it with loading="eager", decoding="sync" and fetchpriority="high", so the browser fetches it before other images instead of waiting. Every other image keeps the default loading="lazy" and decoding="async".
Key Takeaways
- Use
priorityon one image per page: the one that is the Largest Contentful Paint element.- Without it, Astro’s
<Image>lazy-loads by default, which delays a hero image.- Pair it with correct
widthsandsizesso phones download a small file.- For CSS background heroes, preload the image with a
<link rel="preload">built fromgetImage().
Add priority to the hero
---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import hero from '../assets/hero.jpg';
---
<section class="hero">
<Image
src={hero}
alt="Studio desk with laptop and sketches"
widths={[640, 960, 1280, 1920]}
sizes="100vw"
priority
/>
<h1>Websites for small teams</h1>
</section>
The rendered <img> gets three attributes from that one prop:
| Attribute | With priority |
Default |
|---|---|---|
loading |
eager |
lazy |
decoding |
sync |
async |
fetchpriority |
high |
not set |
Any of them can still be overridden by passing the attribute yourself. <Picture> passes the same props through to its fallback <img>, so priority works there too. The Image component guide lists the other props.
Only one image should have it
fetchpriority="high" is a hint about relative order. If five images are marked high, none of them is really ahead. Mark the single image most likely to be the LCP element, usually the hero on landing pages or the cover image on blog posts. In a layout, pass a flag to decide:
---
// src/layouts/BlogPost.astro
import { Image } from 'astro:assets';
const { cover, coverAlt } = Astro.props;
---
{cover && <Image src={cover} alt={coverAlt} widths={[720, 1440]} sizes="(min-width: 768px) 720px, 100vw" priority />}
<slot />
Images in the post body stay lazy, which is what you want.
Get the size right too
A prioritized 3 MB image is still slow. Two things keep the file small:
widthsandsizes. Astro builds asrcsetfromwidths;sizestells the browser how wide the image will be shown, so a phone picks the 640 px file.- Modern formats.
<Image>outputs WebP by default.<Picture formats={['avif', 'webp']}>adds AVIF for browsers that support it.
The responsive images tip explains how to choose sizes values.
CSS background heroes
If the hero is a CSS background, the browser only discovers it after downloading the stylesheet. Generate the optimized URL with getImage() and preload it:
---
// src/components/BackgroundHero.astro
import { getImage } from 'astro:assets';
import bg from '../assets/hero-bg.jpg';
const optimized = await getImage({ src: bg, width: 1920, format: 'webp' });
---
<link rel="preload" as="image" href={optimized.src} fetchpriority="high" />
<section class="hero" style={`background-image: url(${optimized.src})`}>
<slot />
</section>
A <link> inside a component renders where the component sits, usually in <body>. The preload still works there but is found later, so for best results render it in your head component and pass the URL down. Using a real <img> with object-fit: cover is often simpler and gets srcset for free.
Check that it worked
Build and preview, then run Lighthouse or open the Performance panel in Chrome DevTools. The LCP element should be your hero image, and in the Network panel its request should start early with “High” priority. Our LCP guide covers the other parts of LCP, such as server response time and fonts. If you work in a theme from our catalog, the styling docs show where the layout and hero components live.
FAQ
What does priority do on the Astro Image component?
It sets loading="eager", decoding="sync" and fetchpriority="high" on the rendered image, so the browser downloads it early. Without it, images are lazy-loaded with async decoding.
Should I use priority on every image above the fold?
No. Use it on the one image that is the Largest Contentful Paint element. If several images are visible at first, you can set loading="eager" on the others without priority.
Do I still need a preload link with priority?
Usually not for an <img> in the HTML, because the browser finds it while parsing. A preload helps when the image is a CSS background or is inserted by JavaScript.
Why is my LCP image still slow with priority?
Check its file size, your server response time and render-blocking CSS or fonts. priority only changes when the download starts, not how long it takes.