Understanding CSS Custom Properties: ”-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;”
Custom properties (CSS variables) let you define reusable values and make styles easier to maintain. The declaration -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; combines a custom shorthand-like property with two explicit variables to control an element’s animation behavior. This article explains what each part does, how to use them together, and offers practical examples and best practices.
What these properties mean
- -sd-animation: sd-fadeIn;
- This appears to be a custom, project-specific property (prefixed with a hyphen to avoid collisions). It likely names a particular animation behavior — here,
sd-fadeInsuggests a fade-in effect defined elsewhere (e.g., a CSS keyframes block or a utility that maps names to animations).
- This appears to be a custom, project-specific property (prefixed with a hyphen to avoid collisions). It likely names a particular animation behavior — here,
- –sd-duration: 250ms;
- A CSS custom property specifying how long the animation should run. Using a variable allows you to change timing consistently across multiple rules.
- –sd-easing: ease-in;
- Another custom property controlling the animation timing function (the easing curve).
ease-instarts slowly and accelerates.
- Another custom property controlling the animation timing function (the easing curve).
How these tie into actual animations
To make these variables do work, you need corresponding CSS that reads them. A simple pattern:
:root {–sd-duration: 250ms; –sd-easing: ease-in;}
[data-anim=”-sd-animation: sd-fadeIn;”] { /* example selector if using an attribute to mark elements / animation-name: sd-fadeIn; animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
And the keyframes:
@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
This setup decouples the animation’s identity (sd-fadeIn) from its configurable timing values, making it easy to adjust durations or easings site-wide or per-component.
Practical usage patterns
- Component-level overrides:
.card { –sd-duration: 400ms; / slower for a heavier component */ –sd-easing: cubic-bezier(.2,.9,.3,1); animation-name: sd-fadeIn; animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing);}
- Theming and responsive animation:
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }}
- Utility classes (if using a utility-first approach):
.u-anim-sd-fadeIn { animation-name: sd-fadeIn; }.u-anim-duration-250 { –sd-duration: 250ms; }.u-anim-ease-in { –sd-easing: ease-in; }
Best practices
- Use clear, consistent naming for custom properties.
- Prefer semantic names (e.g., –motion-medium) mapped to concrete durations.
- Respect user preferences: honor prefers-reduced-motion.
- Avoid overusing animation; focus on purpose—clarity, feedback, or delight.
- Keep motion performant: use transform and opacity rather than layout-affecting properties.
Conclusion
The declaration -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; is a concise way to declare an animation identity alongside configurable timing variables. When tied to keyframes and used thoughtfully (with theming and accessibility in mind), this pattern boosts maintainability and flexibility for UI motion.
Leave a Reply