Web Vitals patterns

A collection of common UX patterns optimized for Core Web Vitals. This collection includes patterns that are often tricky to implement without hurting your Core Web Vitals scores. You can use the code in these examples to help ensure your projects stay on the right track.

Collection cover image


Images can cause layout shifts if they load after the surrounding page has already been rendered. This issue is more prominent in situations where images are slow to load - for example, on a slow connection or when loading an image with a particularly large file size.

<img> tag

<img width="267" height="400" src="dog.jpg">

This image loads without causing layout shifts.

Learn more

Responsive images and art direction

<!-- Using density descriptors -->
<img width="480" height="330"
    srcset="cat-1x.jpg, cat-2x.jpg 2x, cat-3x.jpg 3x"
    alt="Photo of a cat on a green background">
<!-- Using width descriptors -->    
<img width="256" height="128"
    srcset="dog-256w.jpg 256w, dog-512w.jpg 512w, dog-1028w.jpg 1028w"
    alt="Photo of a dog on a orange background">
<!-- Picture tag -->
    <source media="(max-width: 720px)" width="600" height="300" srcset="newyork-rectangle.jpg" />
    <source media="(min-width: 721px)" width="600" height="600" srcset="newyork-square-1x.jpg, newyork-square-2x.jpg 2x, newyork-square-3x.jpg 3x" />
    <img src="newyork-rectangle.jpg" width="600" height="300" alt="Photo of the Empire State Building">

These responsive images load without causing layout shifts.

Learn more