-sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in;
This article explains the CSS custom properties shown in the title, how they affect animations, and practical usage patterns for modern web UI.
What these properties mean
- -sd-animation: custom property naming an animation preset — here
sd-fadeIn, which implies a fade-in effect (opacity from 0 → 1). - –sd-duration: duration of the animation;
0msmeans no visible animation (instant). - –sd-easing: timing-function controlling acceleration;
ease-instarts slow and speeds up.
Why you might see them together
Design systems often expose animation presets via CSS variables so components can opt into consistent motion. Using a preset name plus duration and easing lets designers adjust timing without changing keyframes.
Example: defining the preset
Define a keyframes rule and map the preset name to that keyframes sequence using a helper:
@keyframes sd-fadeIn {from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); }}
/* default variables /:root{ –sd-animation: sd-fadeIn; –sd-duration: 200ms; –sd-easing: ease-out;}
/ helper to apply the animation if duration > 0 */.fade-in { animation-name: var(–sd-animation); animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
Handling 0ms duration
A –sd-duration: 0ms effectively disables visual motion. That can be useful for:
- Preferring instant state changes in reduced-motion contexts.
- During initial render where motion would feel janky.
- Running on low-power devices or when user prefers reduced motion.
To respect users who prefer reduced motion, detect the preference and set duration to 0:
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }}
Making the preset robust
- Provide sensible defaults in :root.
- Allow component-level overrides for delay, iteration, and direction:
.modal { –sd-duration: 240ms; –sd-delay: 40ms; animation-delay: var(–sd-delay, 0ms); animation-iteration-count: 1;}
- Ensure the keyframes include transform and opacity changes for smoother, GPU-accelerated animations.
Accessibility considerations
- Honor prefers-reduced-motion.
- Avoid animations that trigger vestibular disorders (large translations/rotations).
- Use 0ms or disable animations for focus-critical interactions.
Practical examples
- Instant state change: set
–sd-duration: 0msto show/hide UI instantly. - Staggered entrance: increment
–sd-delayacross list items to create a cascading fade-in using the samesd-fadeInpreset. - Theme switch: increase duration for a pronounced transition when toggling themes.
Troubleshooting
- If
animation-nameappears as the literal stringsd-fadeIn, ensure the keyframes name matches and the property is used inanimation-name. - If no animation runs, check computed
animation-duration— zero disables it. - Use
will-change: opacity, transformsparingly to hint at upcoming animations for better performance.
Conclusion
Using variables like -sd-animation, –sd-duration, and –sd-easing gives design systems flexible, consistent motion control. Setting –sd-duration: 0ms is a deliberate tool to disable motion when needed — useful for accessibility, performance, or instant state changes.
Leave a Reply