Fits

Understanding CSS Custom Properties: ”-sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in;”

CSS custom properties (variables) let you define reusable values that can be referenced across your styles. The snippet -sd-animation: sd-fadeIn; –sd-duration: 250ms; –sd-easing: ease-in; shows how a component or design system might expose animation settings using custom properties and a vendor-prefixed property for animation name. Below is a concise guide explaining each part, how to use them, and examples to implement a smooth fade-in animation.

What each property does

  • -sd-animation: sd-fadeIn;
    • Likely a component- or framework-specific property (note the leading dash). It sets the animation name to use here sd-fadeIn.
  • –sd-duration: 250ms;
    • A custom property defining the animation duration (250 milliseconds).
  • –sd-easing: ease-in;
    • A custom property defining the timing function for the animation.

Defining the keyframes

Create the keyframes for the named animation:

css
@keyframes sd-fadeIn {from { opacity: 0; transform: translateY(6px); }  to   { opacity: 1; transform: translateY(0); }}

Using the custom properties in a component

Reference the variables when applying the animation. Include a fallback for animation name if needed.

css
.component {  /* Fallbacks provided using var() second argument /  animation-name: var(–sd-animation-name, sd-fadeIn);  animation-duration: var(–sd-duration, 250ms);  animation-timing-function: var(–sd-easing, ease-in);  animation-fill-mode: both;  / If the design system uses a prefixed property */  -sd-animation: sd-fadeIn;}

If the intent is to use the custom property -sd-animation as the source for the animation name, expose it via another custom property:

css
:root {  –sd-animation-name: sd-fadeIn;  –sd-duration: 250ms;  –sd-easing: ease-in;}.component {  animation-name: var(–sd-animation-name);  animation-duration: var(–sd-duration);  animation-timing-function: var(–sd-easing);  animation-fill-mode: both;}

Toggling the animation with classes (JS example)

html
<button id=“show”>Show</button><div id=“panel” class=“component hidden”>Content</div>
css
.hidden { opacity: 0; pointer-events: none; }.visible { opacity: 1; animation: sd-fadeIn var(–sd-duration) var(–sd-easing) both; }
js
document.getElementById(‘show’).addEventListener(‘click’, () => {  const panel = document.getElementById(‘panel’);  panel.classList.remove(‘hidden’);  panel.classList.add(‘visible’);});

Accessibility and performance tips

  • Keep durations short for system responsiveness; 200–300ms is common for micro-interactions.
  • Respect user preferences: honor prefers-reduced-motion to disable or reduce animations.
css
@media (prefers-reduced-motion: reduce) {  .component { animation: none; transition: none; }}
  • Avoid animating layout-affecting properties; prefer opacity and transform for smoother performance.

Summary

The snippet exposes a compact, reusable animation configuration pattern using CSS custom properties and a named keyframe. Define keyframes for sd-fadeIn, use the variables for duration and easing, provide sensible fallbacks, and respect accessibility preferences for the best user experience.

Your email address will not be published. Required fields are marked *