Skip to main content
← 🎨 CSS as a design systemΒ·Module B7 Β· Lesson 9
TaskBuild a toast with @starting-style. .toast has transition: opacity 0.3s, transform 0.3s. .toast (final) has opacity: 1, transform: translateY(0). @starting-style { .toast { opacity: 0; transform: translateY(20px); } }. Plus padding 12px 20px, background #18181B, color white, border-radius 8px, max-width 320px.

@starting-style: animate from initial

75 XP6 min
Theory

A 2024 feature for "enter" animations on dynamically-added elements

When you add an element to the DOM, transitions don't fire β€” the element is already in its final state. Workarounds were hacky (force a reflow, JS double-RAF).

The new way:

@starting-style {
  .toast {
    opacity: 0;
    transform: translateY(20px);
  }
}

.toast {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s, transform 0.3s;
}

@starting-style defines the INITIAL state. The actual selector defines the FINAL state. When the element is added (or becomes display: none β†’ visible), the transition runs from initial to final.

Common uses

  • Toast notifications appearing.
  • Popovers / dialogs opening (animate the popover, not the backdrop).
  • Items being added to a list.

Pair with transition

@starting-style alone does nothing β€” you need transition or animation on the element to interpolate between starting and final.

Browser support

Chrome / Edge / Safari shipped 2023-24. Firefox is behind. For wide support, also include the older "force-reflow" fallback or use animation: appear instead.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 10 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.