Understanding the CSS Custom Properties: -sd-animation, –sd-duration, and –sd-easing
These three custom properties are used to control a small animation shorthand and its timing/easing in CSS. Here’s a concise explanation and a practical example you can drop into your stylesheet.
What each property does
- -sd-animation: holds the animation name or shorthand (here
sd-fadeInindicates a fade-in animation). - –sd-duration: sets the animation length (e.g.,
250ms). - –sd-easing: sets the animation timing function (e.g.,
ease-in).
Example implementation
css
:root {–sd-duration: 250ms; –sd-easing: ease-in; –sd-animation: sd-fadeIn;}
/* Define the keyframes referenced by the custom property name /@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/ Apply to elements using the custom properties /.animated { animation-name: var(–sd-animation); animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both; / optional performance and smoothing / backface-visibility: hidden; will-change: opacity, transform;}
/ Example: staggered usage */.animated.delay-1 { animation-delay: 50ms; }.animated.delay-2 { animation-delay: 100ms; }
Usage tips
- Use short durations (150–350ms) for UI micro-interactions; 250ms is a good default.
- Prefer hardware-accelerated properties (opacity, transform) for smoother animations.
- Combine with
animation-fill-mode: bothto retain end state. - Control via variables for theming or accessibility: set duration to
0msfor users who prefer reduced motion.
Accessibility
Respect user preferences:
css
@media (prefers-reduced-motion: reduce) { .animated { animation: none !important; }}
This setup gives you a reusable, accessible fade-in animation controlled entirely with custom properties for easy theming and maintenance.
Leave a Reply