Introduction
Reduced motion support helps make websites easier to use for people who get dizzy or uncomfortable with animations.
Reduced motion support helps make websites easier to use for people who get dizzy or uncomfortable with animations.
@media (prefers-reduced-motion: reduce) {
/* CSS rules to reduce or remove animations */
}animated class if the user prefers reduced motion.@media (prefers-reduced-motion: reduce) {
.animated {
animation: none !important;
transition: none !important;
}
}@media (prefers-reduced-motion: reduce) {
body {
scroll-behavior: auto;
}
}This page shows a blue box that moves left and right using animation. If the user has set their system to prefer reduced motion, the animation stops, making the box stay still.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Reduced Motion Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> <style> .box { width: 5rem; height: 5rem; background-color: #0d6efd; margin: 2rem auto; animation: move 3s infinite alternate; } @keyframes move { from { transform: translateX(0); } to { transform: translateX(10rem); } } @media (prefers-reduced-motion: reduce) { .box { animation: none !important; } } </style> </head> <body> <main class="container text-center"> <h1 class="my-4">Reduced Motion Support</h1> <div class="box" aria-label="Animated blue box"></div> <p>If your system prefers reduced motion, the blue box will not move.</p> </main> </body> </html>
Test reduced motion by changing your system settings or using browser DevTools to simulate it.
Always provide a fallback or simpler experience for users who prefer less motion.
Use @media (prefers-reduced-motion: reduce) to detect user preference.
Turn off or simplify animations inside this media query.
This improves accessibility and user comfort.
@media (prefers-reduced-motion: reduce) in Bootstrap?@media (prefers-reduced-motion: reduce) checks if the user has requested reduced motion in their system settings.@media (prefers-reduced-motion: reduce).div {
animation: slide 2s infinite;
}
@media (prefers-reduced-motion: reduce) {
div {
animation: none;
}
}animation: none; on the div, stopping the animation.@media prefers-reduced-motion: reduce {
.btn {
animation: none;
}
}@media (prefers-reduced-motion: reduce).@media (prefers-reduced-motion: reduce) apply when user requests reduced motion.animation: none !important; and transition: none !important; ensures Bootstrap's fade animations are turned off.Pass the test and this pattern moves unknown