Understanding ”-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;”
These three CSS custom properties (CSS variables) form a concise, modern pattern for controlling a simple fade-in animation on an element. They separate the animation selection, duration, and timing function into reusable variables so styles stay flexible and maintainable.
What each property does
- -sd-animation: sd-fadeIn;
Names the animation to apply. This variable typically maps to a CSS @keyframes rule (for example,sd-fadeIn) defined elsewhere in your stylesheet. - –sd-duration: 250ms;
Controls how long the animation runs. Using a variable allows easy adjustments across components or themes. - –sd-easing: ease-in;
Sets the timing function for the animation, affecting acceleration.ease-instarts slowly and speeds up toward the end.
Example usage
Define the keyframes and a utility animation rule that reads these variables:
css
@keyframes sd-fadeIn {from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
.sd-animated { animation-name: var(–sd-animation); animation-duration: var(–sd-duration, 250ms); animation-timing-function: var(–sd-easing, ease-in); animation-fill-mode: both;}
Apply with different values per element:
css
.card { –sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;}.toast { –sd-animation: sd-fadeIn; –sd-duration: 120ms; –sd-easing: cubic-bezier(.2, .9, .3, 1);}
Why use this pattern
- Reusability: Swap animation, duration, or easing without changing the component’s core CSS.
- Theming: Different themes can override variables globally.
- Maintainability: Centralizes animation definitions and makes tuning easier.
Tips and accessibility
- Prefer durations between 100ms–400ms for micro-interactions to feel responsive.
- Avoid excessive motion for users who prefer reduced motion—honor the media query:
css
@media (prefers-reduced-motion: reduce) { .sd-animated { animation: none; transition: none; }}
- Combine opacity with subtle transform (translateY/scale) for more natural motion.
Conclusion
Using variables like -sd-animation, –sd-duration, and –sd-easing gives you a clean, flexible way to manage animations across a project. Define the keyframes once, then fine-tune behavior per component by overriding these variables.
Leave a Reply