Understanding -sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in;
The CSS-like declaration -sd-animation: sd-fadeIn; –sd-duration: 0ms; –sd-easing: ease-in; looks like a hybrid of a custom property and a vendor-prefixed animation shorthand. It appears intended to drive a simple fade-in effect using CSS custom properties and a design system prefix (-sd-). Below is a clear explanation of each part, why it might be written this way, and how to implement the intended behavior correctly in modern CSS.
What each part means
- -sd-animation: sd-fadeIn;
- Likely a custom property or design-system-specific shorthand that references a named animation (
sd-fadeIn). Not a standard CSS property; probably used by a build step, JavaScript, or a design system to map to real keyframes or animation rules.
- Likely a custom property or design-system-specific shorthand that references a named animation (
- –sd-duration: 0ms;
- A CSS custom property (variable) intended to hold the animation duration.
0msdisables visible animation (instant change). Useful as a default to avoid animations unless explicitly enabled.
- A CSS custom property (variable) intended to hold the animation duration.
- –sd-easing: ease-in;
- A CSS custom property for the timing function controlling acceleration of the animation.
Why 0ms might be used
- Accessibility: some projects default animation durations to
0msand let users or scripts opt into motion to respect reduced-motion preferences. - Performance: instant state changes avoid layout thrash during initial render.
- Feature flagging: animation enabled only when another variable is set.
How to implement a working fade-in using these variables
Assuming the design system exposes sd-fadeIn keyframes or you create your own, here’s a minimal CSS pattern that uses the custom properties:
:root {–sd-duration: 300ms; /* sensible default / –sd-easing: ease-in;}
/ define keyframes (if not provided by the system) /@keyframes sd-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); }}
/ utility class that uses the variables /.sd-animate { animation-name: sd-fadeIn; animation-duration: var(–sd-duration); animation-timing-function: var(–sd-easing); animation-fill-mode: both;}
To respect user reduced motion settings and to allow toggling, you can combine with prefers-reduced-motion and runtime overrides:
@media (prefers-reduced-motion: reduce) { :root { –sd-duration: 0ms; }}
/ example override to enable animation on a specific element */.card { –sd-duration: 250ms; –sd-easing: cubic-bezier(.2,.8,.2,1);}
JavaScript toggling (optional)
If -sd-animation is read by JS, you can toggle animation by setting a data attribute or style property:
// enable animation on an elementconst el = document.querySelector(’.my-element’);el.style.setProperty(’–sd-duration’, ‘300ms’);el.style.setProperty(’–sd-easing’, ‘ease-out’);el.classList.add(‘sd-animate’);
Best practices
- Use
prefers-reduced-motionto respect users who request reduced motion. - Avoid
0msfor default if you want visible transitions; use0msonly as an opt-out default. - Keep animations short (100–400ms) for perceived performance and snappiness.
- Use transforms and opacity (GPU-friendly) rather than animating layout properties.
- Name custom properties clearly and document how your design system consumes them.
Summary
The snippet `
Leave a Reply