Understanding the CSS Custom Properties: -sd-animation, -sd-duration, and -sd-easing
These three CSS custom properties appear to control a simple animation shorthand used by a component or design system. Here’s a concise breakdown and practical guidance for using them, plus examples you can drop into a stylesheet.
What each property does
- -sd-animation: Specifies the animation name or shorthand for which animation to apply (e.g.,
sd-fadeIn). - -sd-duration: Controls the animation length (e.g.,
0ms,300ms,1s). - -sd-easing: Sets the timing function (e.g.,
ease-in,linear,cubic-bezier(…)).
Typical usage pattern
A component’s CSS reads these custom properties and maps them to real animation rules. Example approach in CSS:
:root {–sd-animation: sd-fadeIn; –sd-duration: 300ms; –sd-easing: ease-in;}
/* Define the keyframes for sd-fadeIn /@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/ Utility that applies the animation using the custom properties /.sd-animated { animation-name: var(–sd-animation); animation-duration: var(–sd-duration, 300ms); animation-timing-function: var(–sd-easing, ease); animation-fill-mode: both;}
Example: instant appearance (0ms)
Your provided values produce an immediate change with no transition:
.element { –sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in;}
/ Applying the animation */.element.sd-animated { animation-name: var(–sd-animation); animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
With –sd-duration: 0ms, the keyframes jump instantly to the final state—useful for toggling appearance without delay or when you want animations disabled.
Tips and variations
- To disable animations globally for accessibility, set
–sd-duration: 0msor respectprefers-reduced-motion:css@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }} - Combine with delays:
–sd-delay: 150ms;thenanimation-delay: var(–sd-delay, 0ms); - Use descriptive names for animations (
sd-fadeIn,sd-slideUp) to keep components predictable. - Provide sensible defaults in the component stylesheet to avoid broken animations when properties are unset.
Quick checklist before using
- Ensure corresponding @keyframes exist for the animation name.
- Provide fallback defaults for duration and easing.
- Consider reduced-motion users by forcing 0ms when preferred.
If you want, I can: generate a set of common sd- animation keyframes (fade, slide, scale) or convert these into a small JS utility that toggles the properties programmatically.
Leave a Reply