The <picture> element is best known for serving different image formats to browsers that support them, for example:

<picture>
  <source type="image/avif">
  <source type="image/webp"> 
  <img src="img/waterfall.jpg" alt="A bottom-up shot of a huge waterfall in Iceland with green moss on either side.">
</picture>

What's easy to miss is that <source> children accept a media attribute, so the same construct doubles as a responsive-image mechanism. The swapped asset doesn't need to share the original's aspect ratio either — you might serve a wide-crop rectangle on a large screen and a tight square on a small one.

Screen dimensions are only one dimension. Brad Frost documented using the media attribute with a prefers-reduced-motion media query to serve a static image in place of a GIF when the visitor has asked for less motion at the system level:

<picture>
  <source media="(prefers-reduced-motion: reduce)"></source> 
  <img alt="brick wall">
</picture>

Manuel's tweet about the pattern drew attention to it recently:

https://twitter.com/mmatuzo/status/1314430894090981376?s=12

Pausing rather than replacing

A related approach, an earlier refinement of Steve Faulkner's idea, avoids dropping the animation outright. Instead you stack the animated and non-animated images on top of each other inside a <details> element, letting the GIF be "played" on demand.

That pattern can be extended to respect the same media query with a bit of JavaScript:

CSS-Tricks star logo