Convert images to WebP or AVIF — Claude Code
JPEGs and PNGs are larger than they need to be in 2026. WebP and AVIF cut sizes by 30-50% at the same visual quality — meaningful LCP improvement.
Fixing this in Claude Code
Anthropic's official terminal coding agent
Claude Code can grep the whole codebase first, plan the change, then edit every affected file. Paste the prompt below into your Claude Code chat and the fix rolls out across the project in one pass.
Using a different tool? Pick your stack:
The prompt for Claude Code
Copy and paste this into your Claude Code chat exactly as-is.
Run Claude Code in the project root and make these exact changes, scanning the whole codebase first: Use modern image formats 1. Convert JPEG/PNG images to WebP or AVIF format. 2. Use <picture> element with fallback for older browsers.
Why this matters
Modern image formats are the #1 lever for image-heavy pages. A 2MB hero JPEG becomes a 500KB WebP with no visible quality loss — ~1.5 seconds off LCP on mobile.
Every modern browser supports WebP (99%+ coverage). AVIF has lower support but is 30% smaller than WebP when it works.
How to use this prompt in Claude Code
- 1. Open your Claude Code project.
- 2. Copy the prompt above with the copy button.
- 3. Paste into the Claude Code chat and send.
- 4. Review the diff, accept the changes, redeploy.
- 5. Verify the fix using the checklist below.
Common mistakes to avoid
- error_outlineConverting but keeping JPEG originals as the primary format.
- error_outlineOver-compressing — artifacts become visible.
- error_outlineNot using `<picture>` with fallback for safety.
How to verify the fix worked
- check_circleChrome DevTools → Network → Img type → sizes reduced.
- check_circleLighthouse → "Serve images in next-gen formats" passes.
- check_circlePageSpeed Insights shows image opportunities gone.
Frequently asked questions
WebP or AVIF?expand_more
Do I lose quality?expand_more
Want all 34 prompts tailored to your Claude Code site?
Pantra scans your site in 10 seconds, detects the stack, and generates the exact prompts that apply — only the ones you actually need.
Scan my siteRelated Claude Code prompts
Improve Largest Contentful Paint (LCP) — Claude Code
Prompt to get LCP under 2.5 seconds — preload the hero image, cut render-blocking, use a proper CDN.
PerformanceFix Core Web Vitals (LCP, CLS, INP) — Claude Code
Prompt to address Google Core Web Vitals thresholds: LCP < 2.5s, CLS < 0.1, INP < 200ms. Works in any AI-coded stack.
ImagesAdd a 1200×630 Open Graph image — Claude Code
Prompt to create and reference a properly-sized og:image so your link previews look professional on LinkedIn, Slack, WhatsApp, X.
ImagesAdd alt text to all images at once — Claude Code
Prompt to walk every <img> tag and add descriptive alt attributes in bulk — fast alternative to one-by-one fixing.