Understanding CSS Custom Properties: ”-sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in;”
Custom properties (CSS variables) let developers create reusable, configurable values for styles. The snippet -sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in; mixes a nonstandard prefixed property with three custom properties and suggests a pattern for controlling an animation system. This article explains what each part likely means, how to use similar variables in real CSS, and practical examples for implementing fade-in animations that are configurable and accessible.
What the snippet represents
- -sd-animation: sd-fadeIn;
- Looks like a vendor- or project-prefixed property (the
-sd-prefix) used to name or toggle a predefined animation. Browsers ignore unknown properties, so this is likely consumed by a build tool, design system, or JavaScript that reads CSS values.
- Looks like a vendor- or project-prefixed property (the
- –sd-duration: 0ms;
- A CSS custom property holding the animation duration. Setting it to
0mseffectively disables visible animation unless changed.
- A CSS custom property holding the animation duration. Setting it to
- –sd-easing: ease-in;
- Another custom property for the easing function (timing function) of the animation.
Why use CSS variables for animations
- Centralized control: Change durations/easings in one place to affect many components.
- Theming: Different themes can override variables to change motion behavior.
- Runtime control: JavaScript can update custom properties on elements to animate dynamically.
- Accessibility: Respect user preferences (e.g., reduce-motion) by adjusting variables.
Example: Implementing a configurable fade-in
CSS:
:root {–sd-duration: 300ms; –sd-easing: ease-out;}
/* Named keyframes matching the animation identifier /@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/ A utility that applies the animation when the custom property is set /.fade-in { animation-name: var(–sd-animation, sd-fadeIn); animation-duration: var(–sd-duration, 300ms); animation-timing-function: var(–sd-easing, ease-out); animation-fill-mode: both;}
HTML:
<div class=“fade-in” style=”–sd-duration: 500ms; –sd-easing: cubic-bezier(.2,.9,.2,1); –sd-animation: sd-fadeIn;”> Content to fade in</div>
JavaScript (optional runtime control):
const el = document.querySelector(’.fade-in’);// Temporarily disable animationel.style.setProperty(’–sd-duration’, ‘0ms’);// Re-enable with a new durationsetTimeout(() => el.style.setProperty(’–sd-duration’, ‘450ms’), 50);
Respect prefers-reduced-motion
Always detect users who prefer reduced motion and adapt:
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }}
Or in JavaScript:
if (window.matchMedia(’(prefers-reduced-motion: reduce)’).matches) { document.documentElement.style.setProperty(’–sd-duration’, ‘0ms’);}
Integrating with design systems or frameworks
- Use prefixed properties like
–sd-to namespace variables and avoid collisions. - Provide utility classes (e.g.,
.sd-animate,.sd-no-animate) and let components opt-in by setting-sd-animation(or a data attribute) read by JS for complex orchestration. - Combine with intersection observers to trigger animations when elements enter the viewport.
Troubleshooting
- Unknown nonstandard properties (like
-sd-animation) do nothing unless your JS or build tools read them. - Ensure keyframe names match the
animation-namevalue or the var fallback. - Use
animation-fill-mode: bothto preserve end state.
Conclusion
The fragment -sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in; is a compact pattern for making animations configurable, themeable, and scriptable. By using namespaced custom properties, keyframes, and respecting user motion preferences, you can build flexible, accessible animation systems that integrate cleanly with design systems and runtime logic.
Leave a Reply