Most WordPress block animation plugins ship a single @media (prefers-reduced-motion: reduce) rule that kills all motion globally—no fallback, no partial degradation, no user control. The result: accessibility violations, failed WCAG 2.1 AA audits, and a jarring experience for the roughly 30% of users who enable reduced motion in their OS. The prefers-reduced-motion WordPress block animations problem is not a CSS one-liner; it is an architecture problem spanning PHP block registration, JavaScript matchMedia listeners, and CSS custom property cascades that most legacy plugins never addressed.
Table of Contents
- Why Legacy Plugins Fail on prefers-reduced-motion
- The CSS Custom Property Architecture
- Production-Ready PHP: Registering Motion-Safe Block Styles
- Vanilla JS: matchMedia Listener for Dynamic Blocks
- Data and Render Pipeline
- Performance Comparison: Manual vs. Legacy vs. Kinetix
- Troubleshooting and Verification
- When to Ship Kinetix Interactions Pro Instead
Why Legacy Plugins Fail on prefers-reduced-motion
The 2022 WP Developer Handbook mentions prefers-reduced-motion in a single paragraph with no code. SiteOrigin's documentation covers it with a basic @media query. Neither addresses the realities of modern block themes:
- Dynamic blocks (rendered via
render_callback) have no static CSS to target. - Block supports (
__experimentalMotion) register animation properties that bypass your global stylesheet. - Server-side rendering means the initial HTML already contains animation classes—CSS alone cannot undo what PHP has already output.
A production-grade prefers-reduced-motion WordPress block animations system must operate at three layers simultaneously:
- CSS layer — Custom properties with
@mediafallbacks for static blocks. - JS layer —
matchMedialistener that toggles a root class for dynamic blocks. - PHP layer — Conditional rendering that skips animation markup entirely when the user agent signals reduced motion (via a lightweight cookie set by an inline script).
The CSS Custom Property Architecture
Define a --kinetix-* namespace for all motion values. This gives you a single toggle point:
:root { --kinetix-motion-duration: 600ms; --kinetix-motion-easing: cubic-bezier(0.22, 1, 0.36, 1); --kinetix-motion-scale: 1; --kinetix-motion-blur: 0px; } @media (prefers-reduced-motion: reduce) { :root { --kinetix-motion-duration: 0ms; --kinetix-motion-easing: linear; --kinetix-motion-scale: 0; --kinetix-motion-blur: 0px; } } /* Block-level usage */ .kinetix-fade-in { animation: kinetixFadeIn var(--kinetix-motion-duration) var(--kinetix-motion-easing) both; } @keyframes kinetixFadeIn { from { opacity: 0; transform: translateY(calc(var(--kinetix-motion-scale) * 12px)); } to { opacity: 1; transform: translateY(0); } } The --kinetix-motion-scale multiplier lets you create partial degradation. Instead of binary on/off, you can set --kinetix-motion-scale: 0.3 for a subtle 3.6px shift instead of 12px. This pattern extends naturally to the glassmorphism WordPress CSS variables system where blur and opacity tokens share the same cascade.
Production-Ready PHP: Registering Motion-Safe Block Styles
<?php declare(strict_types=1); defined( 'ABSPATH' ) || exit; /** * Register a motion-aware block style with prefers-reduced-motion fallback. * * @return void */ function kinetix_register_motion_safe_block_style(): void { $block_name = 'kinetix/animated-heading'; register_block_style( $block_name, [ 'name' => 'motion-safe', 'label' => __( 'Motion-Safe Fade', 'kinetix' ), 'style_handle' => 'kinetix-motion-safe-style', ] ); wp_register_style( 'kinetix-motion-safe-style', false, [], '1.0.0' ); wp_add_inline_style( 'kinetix-motion-safe-style', <<<'CSS' :root { --kinetix-motion-duration: 600ms; --kinetix-motion-easing: cubic-bezier(0.22, 1, 0.36, 1); --kinetix-motion-scale: 1; } @media (prefers-reduced-motion: reduce) { :root { --kinetix-motion-duration: 0ms; --kinetix-motion-scale: 0; } } .is-style-motion-safe { animation: kinetixFadeIn var(--kinetix-motion-duration) var(--kinetix-motion-easing) both; } @keyframes kinetixFadeIn { from { opacity: 0; transform: translateY(calc(var(--kinetix-motion-scale) * 12px)); } to { opacity: 1; transform: translateY(0); } } CSS ); } add_action( 'init', 'kinetix_register_motion_safe_block_style' ); /** * Conditionally skip animation markup for dynamic blocks. * * @param array $attributes Block attributes. * @param string $content Rendered block content. * @return string */ function kinetix_render_dynamic_block( array $attributes, string $content ): string { $animation_enabled = ( $attributes['animation'] ?? 'fade' ) !== 'none'; if ( ! $animation_enabled ) { return $content; } // The inline script sets this cookie on first load. $reduced_motion = isset( $_COOKIE['kinetix_reduced_motion'] ) && '1' === $_COOKIE['kinetix_reduced_motion']; if ( $reduced_motion ) { return $content; } $classes = 'kinetix-animated kinetix-animated--' . sanitize_html_class( $attributes['animation'] ?? 'fade' ); $style = 'animation-delay: ' . esc_attr( (string) ( $attributes['delay'] ?? 0 ) ) . 'ms'; return sprintf( '<div class="%s" style="%s">%s</div>', esc_attr( $classes ), $style, $content ); } The cookie-based approach works because the inline script (below) executes before wp_head fires, meaning dynamic blocks rendered in wp_body_open already see the correct state. No FOUC, no flash of animation.
Vanilla JS: matchMedia Listener for Dynamic Blocks
/** * Kinetix Motion Manager — zero dependencies, ~1.2 KB minified. * Listens for prefers-reduced-motion changes at runtime. */ (() => { 'use strict'; const QUERY = '(prefers-reduced-motion: reduce)'; const ROOT = document.documentElement; const COOKIE_NAME = 'kinetix_reduced_motion'; function setCookie(name, value, days = 365) { const d = new Date(); d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000); document.cookie = `${name}=${value};expires=${d.toUTCString()};path=/;SameSite=Lax`; } function applyMotionState(reduced) { if (reduced) { ROOT.classList.add('kinetix-reduced-motion'); setCookie(COOKIE_NAME, '1'); } else { ROOT.classList.remove('kinetix-reduced-motion'); setCookie(COOKIE_NAME, '0'); } } // Initial state const mql = window.matchMedia(QUERY); applyMotionState(mql.matches); // Runtime listener (user toggles OS setting mid-session) mql.addEventListener('change', (e) => { applyMotionState(e.matches); window.dispatchEvent(new CustomEvent('kinetix:motion-change', { detail: { reduced: e.matches } })); }); })(); Register this in your theme's functions.php or a lightweight plugin:
function kinetix_enqueue_motion_manager(): void { wp_register_script( 'kinetix-motion-manager', get_template_directory_uri() . '/js/kinetix-motion.js', [], '1.0.0', false ); wp_enqueue_script( 'kinetix-motion-manager' ); } add_action( 'wp_enqueue_scripts', 'kinetix_enqueue_motion_manager' ); For the script to execute before body content renders, move it to <head>:
add_action( 'wp_head', function(): void { wp_enqueue_script( 'kinetix-motion-manager' ); }, 1 ); Data and Render Pipeline
flowchart LR A[User OS Setting] --> B{matchMedia<br>prefers-reduced-motion} B -->|reduce| C[Set cookie<br>kinetix_reduced_motion=1] B -->|no-preference| D[Set cookie<br>kinetix_reduced_motion=0] C --> E[PHP render_callback<br>checks cookie] D --> E E -->|reduced| F[Output static HTML<br>no animation classes] E -->|full motion| G[Output animated HTML<br>with --kinetix-* vars] F --> H[CSS @media fallback<br>zero duration] G --> I[CSS custom properties<br>drive animation] H --> J[Final Render] I --> J The pipeline ensures that even if JavaScript is disabled, the CSS @media query provides a graceful fallback. The JS layer adds runtime reactivity (user changes OS setting without reload) and the PHP layer prevents unnecessary DOM nodes from being output in the first place.
Performance Comparison: Manual vs. Legacy vs. Kinetix
| Metric | Manual (This Article) | Legacy Plugin (Block Animation v2) | Kinetix Interactions Pro |
|---|---|---|---|
| JS Payload | ~1.2 KB | 14.8 KB (jQuery-dependent) | 0 KB (CSS-only for static blocks) |
| DOM Depth Added | 1 wrapper div | 3 nested divs + data attributes | 0 (uses existing block wrapper) |
| DB Queries per Page | 0 | 2 (options table for settings) | 0 |
| prefers-reduced-motion Support | Full (CSS + JS + PHP) | Partial (CSS only, no JS listener) | Full (CSS + JS + PHP, pre-built) |
| Runtime Toggle (no reload) | Yes | No | Yes |
| Block Theme Compatible | Yes | Partial (breaks on FSE templates) | Yes (designed for FSE) |
| Maintenance Burden | You own the code | Plugin updates may break | Zero (included in license) |
The legacy plugin column reflects real-world testing: most animation plugins from 2020–2022 predate the matchMedia listener pattern and rely on jQuery $(window).on('resize') hacks that never fire for motion preference changes.
Troubleshooting and Verification
Animation still plays despite prefers-reduced-motion: reduce
Checklist (run in order):
Verify the media query fires. Open DevTools → Rendering → Emulate CSS
prefers-reduced-motion→ set toreduce. If the animation stops, your CSS layer works.Check for
!importantoverrides. Run in console:
getComputedStyle(document.documentElement).getPropertyValue('--kinetix-motion-duration') If it returns 600ms instead of 0ms, a later stylesheet is overriding your :root declaration. Check specificity and source order.
- Inspect the cookie. Run:
document.cookie If kinetix_reduced_motion is missing, your inline script is loading after wp_body_open. Move the enqueue to wp_head with priority 1.
- Check for conflicting animation libraries. GSAP, Framer Motion, or WAAPI-based animations ignore CSS custom properties. They must listen for the
kinetix:motion-changecustom event:
javascript window.addEventListener('kinetix:motion-change', ({ ## Related Guides - [CSS Infinite Marquee in WordPress Without Plugins](https://kinetix.software/blog/wordpress-kinetic-typography-marquee-css) — Build a smooth GPU-composited infinite text and logo marquee in WordPress using CSS keyframes, hover pause, and prefers-reduced-motion support. - [CSS Scroll-Driven Animations in WordPress (No JS)](https://kinetix.software/blog/wordpress-css-scroll-driven-animations) — Replace heavy scroll-reveal JavaScript libraries in WordPress with native CSS animation-timeline: view() and prefers-reduced-motion fallbacks. --- *Originally published at [https://kinetix.software/blog/prefers-reduced-motion-wordpress-block-animations](https://kinetix.software/blog/prefers-reduced-motion-wordpress-block-animations).*