Understanding the CSS Custom Properties: -sd-animation, –sd-duration, and –sd-easing
These three CSS custom properties—-sd-animation, –sd-duration, and –sd-easing—are simple, readable tokens you can add to your component styles to control a small, reusable animation pattern. Below is a concise guide showing what each property represents, how to use them together, and a minimal implementation you can drop into a project.
What each property does
- -sd-animation: the animation name or shorthand identifier (example value:
sd-fadeIn) applied to the element. - –sd-duration: the animation duration (example value:
250ms). - –sd-easing: the animation timing function (example value:
ease-in).
Minimal CSS implementation
css
:root {–sd-duration: 250ms; –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 reads the custom properties */.sd-animated { animation-name: var(–sd-animation, sd-fadeIn); animation-duration: var(–sd-duration, 250ms); animation-timing-function: var(–sd-easing, ease-in); animation-fill-mode: both;}
Usage examples
- Apply default fade-in:
html
<div class=“sd-animated”>Hello</div>
- Override duration and easing on a specific element:
html
<div class=“sd-animated” style=”–sd-duration:500ms; –sd-easing:cubic-bezier(.2,.9,.2,1);”> Slower, smoother fade</div>
Tips
- Keep motion preference in mind: respect reduced-motion by disabling animations when the user prefers reduced motion.
- Use logical defaults in :root so components work without inline overrides.
- Combine with opacity and transform for smooth, performant animations.
Respect reduced-motion
css
@media (prefers-reduced-motion: reduce) { .sd-animated { animation: none; transition: none; }}
This pattern makes animations configurable and consistent across components while keeping the CSS declarative and easy to override.
Leave a Reply