Disabling Autoplay and Infinite Loops
You'll learn how to respect user preferences by turning off autoplaying and infinitely looping animations when motion sensitivity is detected.
The Core Idea
Some animations run automatically when a page loads (autoplay) or repeat forever (infinite loops). For users with vestibular disorders or motion sensitivity, these can cause dizziness, nausea, or discomfort. When a user has enabled prefers-reduced-motion, you should stop these animations from starting automatically or limit them to a single cycle instead of looping endlessly.
How It Works
Inside a @media (prefers-reduced-motion: reduce) block, you can override animation properties to disable problematic behaviors:
/* Normal animation - infinite loop */
.spinner {
animation: spin 2s linear infinite;
}
/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
.spinner {
animation: none; /* Completely stop the animation */
}
}
For animations that provide important feedback (like a loading indicator), you might show a static version instead of removing it entirely:
.loading {
animation: pulse 1.5s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
.loading {
animation: none;
opacity: 0.8; /* Show static indicator instead */
}
}
Think of It This Way
Imagine a carousel that automatically rotates through slides forever. For someone sensitive to motion, it's like being on a merry-go-round they can't stop. When they signal "I prefer less motion," you should pause that carousel or let it complete just one rotation.
Key Takeaway: Always disable animation-iteration-count: infinite and autoplay behaviors inside your prefers-reduced-motion: reduce media queries—either remove the animation entirely or limit it to a single, essential cycle.