# Minimal CSS play/pause gif #code Default: Animation plays. Stops when clicked. Prefers reduced motion: Animation stopped. Plays when clicked. This works at least as far back as Netscape 7.2 from 2004. ```css .gif input { position: absolute; left: -9999px; } .gif input + img + img, .gif :checked + img { display: none; } .gif :checked + img + img { display: inline; } @media (prefers-reduced-motion: reduce) { .gif input + img, .gif :checked + img + img { display: none; } .gif input + img + img, .gif :checked + img { display: inline; } } ``` ```html ```


You can get rid of the media query if you switch the order of the ``s. Then gifs will default to paused regardless of motion preference. ```css .gif input { position: absolute; left: -9999px; } .gif input + img + img, .gif :checked + img { display: none; } .gif :checked + img + img { display: inline; } ``` ```html ```


One downside of this approach is that the naked HTML will show both images (and the checkbox). We're stuck with the checkbox, but we can hide one of the images. ```css .gif input { position: absolute; left: -9999px; } .gif img { width: auto; height: auto; } .gif input + img + img, .gif :checked + img { display: none; } .gif :checked + img + img { display: inline; } ``` ```html ```


And with the media query: ```css .gif input { position: absolute; left: -9999px; } .gif img { width: auto; height: auto; } .gif input + img + img, .gif :checked + img { display: none; } .gif :checked + img + img { display: inline; } @media (prefers-reduced-motion: reduce) { .gif input + img, .gif :checked + img + img { display: none; } .gif input + img + img, .gif :checked + img { display: inline; } } ``` ```html ```