Understanding CSS Custom Properties for Animations: –sd-animation, –sd-duration, –sd-easing
Custom properties (CSS variables) let designers create reusable, themeable values for animations. The snippet -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; shows a concise pattern for controlling an element’s entrance animation. Below is a practical breakdown, usage examples, and tips.
What each property means
- -sd-animation: sd-fadeIn;
Likely a shorthand or project-specific custom property naming convention that indicates which animation to apply — here, a fade-in effect namedsd-fadeIn. The leading hyphen suggests a vendor-like or scoped variable. - –sd-duration: 250ms;
Controls how long the animation runs. Using a variable makes it easy to adjust timing across components. - –sd-easing: ease-in;
Defines the timing function for the animation’s acceleration curve.
How to implement with CSS
- Define the keyframes for
sd-fadeIn:
css
@keyframes sd-fadeIn {from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
- Create a base animation rule that reads the variables:
css
.animated { animation-name: var(–sd-animation); animation-duration: var(–sd-duration, 250ms); animation-timing-function: var(–sd-easing, ease); animation-fill-mode: both;}
- Use the scoped shorthand shown (note: normalize the property name):
css
.component { –sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;}
HTML example
html
<div class=“component animated”> Content that fades in</div>
Variations and best practices
- Provide sensible fallbacks in the
var()calls (e.g.,var(–sd-duration, 300ms)). - Use meaningful naming conventions and avoid collision with native or vendor properties.
- Prefer
animation-durationin milliseconds for small UI animations; use seconds for longer transitions. - Combine transforms (translate, scale) with opacity for smoother perceived motion.
- Respect reduced-motion preferences:
css
@media (prefers-reduced-motion: reduce) { .animated { animation: none !important; }}
When to use this pattern
- Component libraries where tokens control consistent motion across elements.
- Theming systems allowing designers to tweak motion intensity without touching keyframes.
- Scoped styles in web components or CSS modules to keep animation names isolated.
Quick checklist before shipping
- Confirm the variable names are documented for other developers.
- Test across browsers for variable and animation support.
- Ensure accessibility by honoring reduced-motion and avoiding sudden flashes.
This pattern offers a flexible, maintainable way to manage UI motion by decoupling animation names and parameters from component styles.
Leave a Reply