brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: prefers-reduced-motion in css switches off animation for people who ask for it

Css
~/tips/tip-css-prefers-reduced-motion-media

@media (prefers-reduced-motion: reduce) {

Detects the reduced-motion setting of the operating system so animations can be switched off.

Motion that feels smooth to me can make other people dizzy.

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

The media query matches when the visitor enabled a reduced-motion setting in the operating system. The block above is the blunt version: it shortens every animation and transition to almost nothing and turns off smooth scrolling. A more careful way is to put your decorative animations inside @media (prefers-reduced-motion: no-preference) so they only run for people who did not ask for less. Test it by switching the setting on in macOS Accessibility or in the browser devtools rendering panel.

Further reading: MDN: prefers-reduced-motion

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link