-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;
This article explains what the CSS-like shorthand shown in the title represents, when and how to use it, and practical patterns for implementing similar animation variables in modern front-end projects.
What this syntax is
- Custom properties (CSS variables): The double-dash prefix (–) marks CSS custom properties. They hold values you can reference elsewhere with var().
- Namespacing convention: The leading
-sd-looks like a namespace or design-system prefix to avoid collisions with other variables. - Animation intent:
sd-fadeInlikely names an animation or keyframe behavior. The other properties declare duration and easing.
Why use this pattern
- Reusability: Centralize animation values to keep motion consistent across components.
- Theming: Swap variable values for different themes or motion preferences.
- Maintainability: Changing the variable updates all components that use it.
How to implement (example patterns)
- Define keyframes and a mapping for semantic animation names:
css
@keyframes sd-fadeIn {from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
:root { –sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;}
- Apply variables in a component:
css
.card { animation-name: var(–sd-animation); animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
- Component-level overrides:
css
.modal { –sd-duration: 150ms; –sd-easing: cubic-bezier(.2, .8, .2, 1);}
- Respect user motion preferences:
css
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; } .card { animation: none; transition: none; }}
Advanced patterns
- Multiple animations: Store a full shorthand in one variable:
–sd-animation: sd-fadeIn 250ms ease-in both;then apply withanimation: var(–sd-animation); - JS-driven swaps: Toggle CSS variable values from JavaScript for runtime control:
js
el.style.setProperty(’–sd-animation’, ‘sd-slideIn’);el.style.setProperty(’–sd-duration’, ‘350ms’);
- Design tokens: Export these variables from a design-token system so motion scales with brand guidelines.
Troubleshooting
- If animation-name seems ignored, ensure the keyframes name matches the variable value exactly.
- Check specificity: component-level variables override root ones.
- Animations don’t run on display: none; use visibility/opacity instead.
Best practices
- Use short durations for micro-interactions (100–250ms), longer for larger transitions (300–500ms).
- Prefer easing curves that match the intent: ease-out for entrance, ease-in for exits.
- Always honor prefers-reduced-motion.
Conclusion
The snippet -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; is a compact, maintainable way to express animation intent using CSS custom properties. Use it to centralize motion, enable theming, and keep UI transitions consistent across your project.
Leave a Reply