prefers-reduced-motion media query, Avoiding flashing content

Accessibility experience : Users with Motor disability and prefers-reduced-motion

Reduced-motion media query, Avoiding flashing content #

Description:

Using the prefers-reduced-motion media query allows you to respect users’ preferences to minimize motion, which can improve accessibility for individuals with motion sensitivity. Flashing or fast-moving content can trigger discomfort, nausea, or even seizures in some users. By detecting this preference, you can adjust or disable animations, transitions, or flashing content accordingly.

Here’s how to use the prefers-reduced-motion media query to create a more accessible experience by avoiding or minimizing motion and flashing content.

Example: Using prefers-reduced-motion to Reduce or Disable Animations

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Accessible Reduced Motion Example</title>
    <style>
        /* Default animation for elements */
        .animated-content {
            animation: slideIn 2s ease-in-out;
        }
        /* Keyframes for default slide-in animation */
        @keyframes slideIn {
            from { transform: translateX(-100%); }
            to { transform: translateX(0); }
        }
        /* Reduced motion: Remove animations */
        @media (prefers-reduced-motion: reduce) {
            .animated-content {
                animation: none;
            }
        }
        /* Example flashing content (default state) */
        .flashing-content {
            animation: flash 0.5s infinite;
        }
        /* Keyframes for flashing */
        @keyframes flash {
            0%, 100% { opacity: 1; }
            50% { opacity: 0; }
        }
        /* Disable flashing animation for reduced motion preference */
        @media (prefers-reduced-motion: reduce) {
            .flashing-content {
                animation: none;
            }
        }
    </style>
</head>
<body>
    <h1>Product Overview</h1>
    <p>This is an example of using <code>prefers-reduced-motion</code> to respect users' motion preferences.</p>
    <!-- Content with slide-in animation -->
    <div class="animated-content">
        <h2>Special Offer</h2>
        <p>Get 20% off your first purchase!</p>
    </div>
    <!-- Flashing content (e.g., alert or promotional banner) -->
    <div class="flashing-content" role="alert" aria-live="polite">
        Limited Time Offer - Free Shipping on Orders Over $50!
    </div>
</body>
</html>

Explanation #

  1. Slide-In Animation (Reduced Motion):
    • The .animated-content div uses a slideIn animation by default, causing it to slide in from the left when loaded.
    • With the prefers-reduced-motion media query, the animation is disabled by setting animation: none. This removes motion for users who have requested reduced motion, preventing potential discomfort.
  2. Flashing Content (Disabled for Reduced Motion):
    • The .flashing-content div is styled with a flashing animation using the flash keyframes, which alternates the opacity to create a blinking effect.
    • Inside the @media (prefers-reduced-motion: reduce) query, the animation is removed to avoid flashing content for users with motion sensitivity, making the content static.
  3. Avoiding Flashing for Seizure Safety:
    • Flashing content, especially at certain frequencies, can trigger seizures in users with photosensitive epilepsy.
    • Reducing or eliminating flashing content when prefers-reduced-motion is enabled helps create a safer browsing environment for these users.

Key Tips for Implementing Reduced Motion #

  • Use the prefers-reduced-motion Media Query: Check if users prefer reduced motion, and disable or minimize animations and transitions accordingly.
  • Avoid Flashing Content Altogether: If flashing or blinking effects are necessary, use low-frequency animations and avoid anything above 3 flashes per second. Implement prefers-reduced-motion to disable flashing for users who have requested reduced motion.
  • Offer Alternative Effects: If visual effects are critical for the design, consider non-moving alternatives for users who prefer reduced motion, such as subtle color changes or static indicators.


Screen reader: NVDA
Video:

What are your feelings

Updated on March 6, 2025