Understanding -sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in;
These CSS custom properties appear to be a simple, modular way to control a small animation system that uses CSS variables to specify the animation name, duration, and easing. Below is a concise guide explaining what each part does, how to implement it, and practical examples you can reuse.
What the properties mean
- -sd-animation: sd-fadeIn;
Sets the animation identifier (here,sd-fadeIn) so a component or stylesheet can apply the corresponding keyframes or behavior. - –sd-duration: 0ms;
Defines the duration of the animation.0msmeans no visible animation (instant state change). Use values like250ms,500ms, or1sfor visible transitions. - –sd-easing: ease-in;
Controls the timing function.ease-instarts slowly and speeds up. Other common values:linear,ease-out,cubic-bezier(…).
Why use CSS variables for animations
- Reusability: Define the animation once (keyframes) and swap names/durations/easing on many elements.
- Runtime theming: Change variables in JS or on parent elements to alter behavior globally.
- Scoped overrides: Component libraries can expose these variables for easy customization without touching core CSS.
Example implementation
CSS:
css
:root {–sd-duration: 300ms; –sd-easing: ease;}
/* Default animation keyframes /@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/ Utility class that reads variables */.sd-animated { animation-name: var(–sd-animation, sd-fadeIn); animation-duration: var(–sd-duration, 300ms); animation-timing-function: var(–sd-easing, ease); animation-fill-mode: both;}
HTML usage:
html
<div class=“sd-animated” style=”–sd-duration: 500ms; –sd-easing: ease-out;”> Visible animated content</div>
When –sd-duration: 0ms is useful
- To toggle animation off quickly without removing animation-related classes.
- For instant state changes in reduced-motion or performance-sensitive contexts.
- To test styles without visual transitions.
Accessibility considerations
- Respect user preferences for reduced motion. Detect with the
prefers-reduced-motionmedia query and set–sd-duration: 0mswhen the user prefers reduced motion.
css
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }}
Tips and best practices
- Keep meaningful defaults in
:rootor a shared component theme. - Use semantic variable names if integrating into a design system (e.g.,
–motion-fast,–motion-slow). - Combine with
animation-delayandanimation-iteration-countvariables for more control. - Test on low-end devices and under reduced-motion settings.
Conclusion
Using CSS variables like -sd-animation, –sd-duration, and –sd-easing creates a flexible, themeable approach to animations. Setting –sd-duration: 0ms effectively disables motion while preserving structure and class names—useful for accessibility and runtime control.
Leave a Reply