UI Components Easy
Reduced Motion Demo
Showcase of CSS prefers-reduced-motion patterns — before/after animations that respect the OS motion preference. Pure CSS.
Open in Lab
MCP
css
Targets: JS HTML
Code
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #0d1117;
color: #e6edf3;
min-height: 100vh;
padding: 32px 16px;
display: flex;
justify-content: center;
}
.demo {
width: 100%;
max-width: 720px;
display: flex;
flex-direction: column;
gap: 20px;
}
.rm-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
background: #161b22;
border: 1px solid #21262d;
border-radius: 10px;
padding: 12px 18px;
gap: 12px;
flex-wrap: wrap;
}
.rm-sys-status {
font-size: 13px;
color: #8b949e;
}
.rm-sys-status.active {
color: #f85149;
}
.rm-sys-status.inactive {
color: #3fb950;
}
.rm-override {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #8b949e;
cursor: pointer;
}
.rm-override input:focus-visible + .rm-override-label {
outline: 2px solid #6366f1;
border-radius: 4px;
}
.rm-override-label {
font-weight: 600;
}
.rm-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
}
.rm-card {
background: #161b22;
border: 1px solid #21262d;
border-radius: 12px;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
min-height: 160px;
justify-content: center;
}
.rm-card--wide {
grid-column: 1 / -1;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
gap: 14px;
}
.rm-label {
font-size: 11px;
font-weight: 700;
color: #4a555f;
text-transform: uppercase;
letter-spacing: 0.06em;
align-self: flex-start;
width: 100%;
}
.rm-caption {
font-size: 11px;
color: #4a555f;
}
.rm-replay-btn {
background: #21262d;
border: 1px solid #30363d;
color: #8b949e;
font-size: 12px;
padding: 5px 12px;
border-radius: 7px;
cursor: pointer;
align-self: flex-start;
}
.rm-replay-btn:hover {
color: #e6edf3;
border-color: #8b949e;
}
/* Animations */
.spin-loader {
width: 36px;
height: 36px;
border: 3px solid #30363d;
border-top-color: #6366f1;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.bounce-ball {
width: 20px;
height: 20px;
background: #6366f1;
border-radius: 50%;
animation: bounce 0.7s ease-in-out infinite alternate;
}
@keyframes bounce {
to {
transform: translateY(-24px);
}
}
.gradient-shift {
width: 100%;
max-width: 120px;
height: 48px;
border-radius: 8px;
background: linear-gradient(270deg, #6366f1, #ec4899, #f59e0b);
background-size: 300% 100%;
animation: grad-shift 3s ease infinite;
}
@keyframes grad-shift {
0%,
100% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
}
.slide-demo {
display: flex;
flex-direction: column;
gap: 8px;
flex: 1;
}
.slide-item {
background: #21262d;
border-radius: 7px;
padding: 8px 14px;
font-size: 13px;
color: #cdd6f4;
opacity: 0;
transform: translateX(-20px);
animation: slide-in 0.5s ease forwards;
}
.slide-item:nth-child(1) {
animation-delay: 0.1s;
}
.slide-item:nth-child(2) {
animation-delay: 0.3s;
}
.slide-item:nth-child(3) {
animation-delay: 0.5s;
}
@keyframes slide-in {
to {
opacity: 1;
transform: translateX(0);
}
}
.parallax-card {
width: 80px;
height: 80px;
border-radius: 12px;
position: relative;
background: #0d1117;
border: 1px solid #30363d;
overflow: hidden;
cursor: pointer;
}
.pc-layer {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.1s;
}
.pc-layer--back {
background: radial-gradient(circle at 30% 30%, #1e1e4e, #0d1117);
}
.pc-layer--mid {
background: transparent;
}
.pc-layer--front {
font-size: 24px;
color: #6366f1;
}
/* Fallbacks */
.fallback-dots {
display: flex;
gap: 6px;
align-items: center;
}
.fallback-dots span {
width: 8px;
height: 8px;
background: #6366f1;
border-radius: 50%;
animation: pulse-dot 1.2s ease-in-out infinite;
}
.fallback-dots span:nth-child(2) {
animation-delay: 0.2s;
}
.fallback-dots span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes pulse-dot {
0%,
100% {
opacity: 0.4;
}
50% {
opacity: 1;
}
}
.fallback-static-ball {
width: 20px;
height: 20px;
background: #6366f1;
border-radius: 50%;
animation: pulse-opacity 2s ease-in-out infinite;
}
@keyframes pulse-opacity {
0%,
100% {
opacity: 0.5;
}
50% {
opacity: 1;
}
}
.fallback-static-grad {
width: 100%;
max-width: 120px;
height: 48px;
border-radius: 8px;
background: linear-gradient(135deg, #6366f1, #ec4899);
}
.fallback-fade-demo {
display: flex;
flex-direction: column;
gap: 8px;
flex: 1;
}
.fade-item {
background: #21262d;
border-radius: 7px;
padding: 8px 14px;
font-size: 13px;
color: #cdd6f4;
opacity: 0;
animation: fade-in 0.4s ease forwards;
}
.fade-item:nth-child(1) {
animation-delay: 0.1s;
}
.fade-item:nth-child(2) {
animation-delay: 0.25s;
}
.fade-item:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes fade-in {
to {
opacity: 1;
}
}
.fallback-static-card {
width: 80px;
height: 80px;
border-radius: 12px;
background: radial-gradient(circle at 30% 30%, #1e1e4e, #0d1117);
border: 1px solid #30363d;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
}
/* Global reduced motion overrides */
@media (prefers-reduced-motion: reduce) {
.rm-anim {
display: none !important;
}
.rm-fallback {
display: flex !important;
}
}
[data-reduced="true"] .rm-anim {
display: none !important;
}
[data-reduced="true"] .rm-fallback {
display: flex !important;
}const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
const statusEl = document.getElementById("rmSysStatus");
const override = document.getElementById("rmOverride");
function updateStatus(reduced) {
if (reduced) {
statusEl.textContent = "System preference: Reduced motion ON";
statusEl.className = "rm-sys-status active";
} else {
statusEl.textContent = "System preference: Reduced motion OFF";
statusEl.className = "rm-sys-status inactive";
}
}
function applyMotion(reduced) {
document.body.dataset.reduced = String(reduced);
}
mq.addEventListener("change", (e) => {
updateStatus(e.matches);
if (!override.checked) applyMotion(e.matches);
});
updateStatus(mq.matches);
applyMotion(mq.matches);
override.addEventListener("change", () => {
applyMotion(override.checked || mq.matches);
});
// Parallax on hover
const card = document.getElementById("parallaxCard");
if (card) {
card.addEventListener("mousemove", (e) => {
if (document.body.dataset.reduced === "true") return;
const rect = card.getBoundingClientRect();
const cx = (e.clientX - rect.left) / rect.width - 0.5;
const cy = (e.clientY - rect.top) / rect.height - 0.5;
card.querySelector(".pc-layer--mid").style.transform = `translate(${cx * 6}px, ${cy * 6}px)`;
card.querySelector(".pc-layer--front").style.transform =
`translate(${cx * 12}px, ${cy * 12}px)`;
});
card.addEventListener("mouseleave", () => {
card.querySelectorAll(".pc-layer").forEach((l) => (l.style.transform = ""));
});
}
// Replay slide/fade animation
document.getElementById("replayBtn").addEventListener("click", () => {
const reduced = document.body.dataset.reduced === "true";
const slide = document.getElementById("slideDemo");
const fade = document.getElementById("fadeFallback");
if (reduced) {
fade.querySelectorAll(".fade-item").forEach((el) => {
el.style.animation = "none";
requestAnimationFrame(() => {
el.style.animation = "";
});
});
} else {
slide.querySelectorAll(".slide-item").forEach((el) => {
el.style.animation = "none";
requestAnimationFrame(() => {
el.style.animation = "";
});
});
}
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reduced Motion Demo</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="demo">
<div class="rm-toolbar">
<span class="rm-sys-status" id="rmSysStatus">System preference: detecting…</span>
<label class="rm-override">
<input type="checkbox" id="rmOverride" />
<span class="rm-override-label">Force reduced motion</span>
</label>
</div>
<div class="rm-grid">
<div class="rm-card">
<div class="rm-label">Spin Loader</div>
<div class="rm-anim spin-loader"></div>
<div class="rm-fallback fallback-dots" hidden>
<span></span><span></span><span></span>
</div>
<div class="rm-caption">Spinner → Pulsing dots</div>
</div>
<div class="rm-card">
<div class="rm-label">Bounce Ball</div>
<div class="rm-anim bounce-ball"></div>
<div class="rm-fallback fallback-static-ball" hidden></div>
<div class="rm-caption">Bounce → Fade</div>
</div>
<div class="rm-card rm-card--wide">
<div class="rm-label">Slide-in Content</div>
<div class="rm-anim slide-demo" id="slideDemo">
<div class="slide-item">Item slides in from left</div>
<div class="slide-item">Staggered appearance</div>
<div class="slide-item">Smooth enter animation</div>
</div>
<div class="rm-fallback fallback-fade-demo" id="fadeFallback" hidden>
<div class="fade-item">Item appears with fade</div>
<div class="fade-item">Simple opacity change</div>
<div class="fade-item">Respects user preference</div>
</div>
<button class="rm-replay-btn" id="replayBtn">↺ Replay</button>
<div class="rm-caption">Slide → Fade</div>
</div>
<div class="rm-card">
<div class="rm-label">Parallax Card</div>
<div class="rm-anim parallax-card" id="parallaxCard">
<div class="pc-layer pc-layer--back"></div>
<div class="pc-layer pc-layer--mid"></div>
<div class="pc-layer pc-layer--front">✦</div>
</div>
<div class="rm-fallback fallback-static-card" hidden>
<div class="fsc-content">✦</div>
</div>
<div class="rm-caption">Parallax → Static</div>
</div>
<div class="rm-card">
<div class="rm-label">Gradient Shift</div>
<div class="rm-anim gradient-shift"></div>
<div class="rm-fallback fallback-static-grad" hidden></div>
<div class="rm-caption">Animated → Static gradient</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>Side-by-side demo of CSS animations paired with @media (prefers-reduced-motion: reduce) overrides. Covers slide-in, spin, bounce, and parallax patterns. Toggle a simulator switch to preview both states.