Back to Blog
Development
WebP
HTML
Picture Element

WebP Implementation Best Practices: Fallbacks, Picture Element & More

2024-10-22 9 min read PicOptimize Team
Code editor showing picture element implementation with WebP, AVIF, and JPEG fallbacks for responsive images

Implementing WebP correctly requires understanding browser support, fallback strategies, and the element. This technical guide provides production-ready code patterns and best practices.

Browser Support (2024)

BrowserVersionSupport Since
Chrome23+2013
Firefox65+2019
Safari14+2020
Edge79+2020
Safari iOS14+2020
Chrome Android25+2013

Global support: 96%+ — Safe for production with fallbacks.

The <picture> Element Pattern

\\\`html

src="hero.jpg"

alt="Hero image description"

width="1920"

height="1080"

loading="eager"

fetchpriority="high"

/>

\\\`

Responsive Images with srcset

\\\`html

type="image/webp"

srcset="

hero-400.webp 400w,

hero-800.webp 800w,

hero-1200.webp 1200w,

hero-1600.webp 1600w

"

sizes="(max-width: 480px) 100vw, (max-width: 768px) 80vw, 1200px"

/>

Hero

\\\`

Next.js Image Component (Recommended)

\\\`tsx

import Image from 'next/image';

src="/hero.jpg"

alt="Hero image"

width={1920}

height={1080}

priority // Preloads, no lazy-loading

sizes="(max-width: 768px) 100vw, 50vw"

placeholder="blur"

blurDataURL="data:image/jpeg;base64,..."

/>

\\\`

CSS Fallback for Background Images

\\\`css

.hero {

background-image: url('hero.jpg');

background-image: image-set(

url('hero.avif') type('image/avif'),

url('hero.webp') type('image/webp'),

url('hero.jpg') type('image/jpeg')

);

}

\\\`

Performance Checklist

Keep Reading