To replace placeholder images in an Astro theme, first check where each image lives. Images in src/assets/ are imported and optimised by astro:assets, so you replace the file (or change the import) and Astro generates new sizes and formats on build. Images in public/ are served as-is, so resize and compress those yourself. Images referenced from content frontmatter are swapped by editing the path in the entry.
Key Takeaways
src/images get optimised;public/images do not.- Replacing a file under the same name is the fastest swap and keeps every import working.
- Content images are paths in frontmatter, checked by the collection’s
image()schema.- Match the original aspect ratio, or crops and layout will shift.
- Every new image needs new
alttext that describes it.
Find where the placeholders come from
# Terminal
grep -rn "\.jpg\|\.png\|\.webp\|\.avif" src/ --include=*.astro --include=*.ts --include=*.md --include=*.mdx | head -40
You will see three patterns:
- Imports in components, such as
import hero from '../assets/hero.jpg', used with<Image src={hero} />. - Frontmatter paths in content entries, such as
cover: ./cover.jpginsrc/content/projects/alpha.md. - Public URLs, such as
<img src="/images/team-1.jpg">, pointing intopublic/images/.
Replace imported images in src/assets
The simplest swap is to overwrite the file with your own image under the same name:
# Terminal
cp ~/Downloads/clinic-reception.jpg src/assets/hero.jpg
Every component that imports hero.jpg picks it up, and astro:assets creates the resized WebP or AVIF versions during npm run build. If you would rather keep meaningful file names, add the new file and change the import:
---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import heroImage from '../assets/clinic-reception.jpg';
---
<Image
src={heroImage}
alt="Reception desk at Harbour Dental with two staff members"
widths={[640, 960, 1280, 1920]}
sizes="100vw"
loading="eager"
fetchpriority="high"
/>
Keep the attributes the theme already set, especially widths, sizes and loading; they were chosen for that layout. Hero images above the fold should stay loading="eager". The Image component guide covers every prop.
Upload a large, high-quality source (around 2,000 pixels wide for full-width images). Astro can scale down but not up, and it only generates widths up to the original’s size.
Replace images in content entries
Projects, team members and blog posts usually reference images from frontmatter. Put the new file next to the entry or in src/assets/, then update the path:
---
# src/content/projects/harbour-dental.md
title: "Harbour Dental rebrand"
cover: ../../assets/projects/harbour-cover.jpg
coverAlt: "Harbour Dental's new sign above the clinic entrance"
---
If the collection schema uses image(), a wrong path fails the build with an “Image not found” error that names the file, which makes broken swaps easy to catch. The image not found fix explains the path rules.
Replace images in public/
Files in public/ are copied to the site untouched: no resizing, no format conversion. Use public/ only for things that need a fixed URL, such as the favicon or the default Open Graph image. For those:
- Export at the exact size used (for example 1200 by 630 for social images).
- Compress before committing; a social image rarely needs to exceed 300 KB.
- Keep the same file name, or update every reference.
If a theme puts content photos in public/, consider moving them to src/assets/ and importing them, so they get optimised. The responsive images tip shows the pattern.
Match aspect ratios and write alt text
Themes often crop images with object-fit: cover inside fixed-ratio boxes. A portrait photo in a landscape slot will crop heads. Crop your images to the original’s ratio before adding them; check the old file’s dimensions with:
# Terminal
sips -g pixelWidth -g pixelHeight src/assets/hero.jpg
(sips is built into macOS; on Linux use identify from ImageMagick.)
Write alt text for each image based on what it shows and why it is there. Decorative background images get alt="". Demo alt text that describes stock photos is one of the most common leftovers after a rebrand.
Rebuild and check
# Terminal
npm run build
npm run preview
Look at each page at mobile and desktop widths, and search the source for any demo file you meant to delete. If you are still choosing, every theme in the Astro themes catalog has a live preview, so you can see which image slots you will need to fill before you buy. If a page shifts as images load, check the layout shift guide.
FAQ
Where are images stored in an Astro theme?
Usually in src/assets/ for images that Astro optimises, next to content entries in src/content/ for posts and projects, and in public/ for files that need a fixed URL, such as the favicon.
Why didn’t my new image change on the Astro site?
The theme may import a different file than the one you replaced, or the browser is showing a cached copy. Search the project for the image name, then restart npm run dev and hard-refresh.
Should I put Astro images in public or src?
Put them in src/ and import them unless they need a fixed URL. Images in src/ are resized and converted to modern formats; images in public/ are served exactly as you upload them.
What size should hero images be in an Astro theme?
Around 2,000 pixels wide for a full-width hero, cropped to the slot’s aspect ratio. Astro generates smaller versions from that source for each widths value.