Animate Entry and Exit with @starting-style: No JavaScript Needed
October 1, 2026 | 9 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
Entry animations in CSS were always easy. Exit animations were the impossible part. The moment you removed an element or flipped it to display: none, it vanished instantly, no transition, no fade, nothing. Developers reached for JavaScript libraries just to animate a dialog closing. That era is over. With @starting-style, transition-behavior: allow-discrete, and the overlay property, both entry and exit animations work in pure CSS, in all modern browsers.
Shortcut: prototype the keyframes for these animations visually in our free CSS Animation Generator, then wire them up with the entry and exit patterns below.
1. Why Exit Animations Were Impossible
Two CSS facts conspired against exit animations. First, display is a discrete property: it has no intermediate values, so it can never transition. An element is either rendered or it is not. Second, transitions need a before and an after state on the same rendered element. When you set display: none, the element leaves the render tree immediately, and the browser has nothing left to animate. The result every developer knows: menus and dialogs that fade in beautifully and disappear with a jarring snap.
2. Entry Animations with @starting-style
The @starting-style rule solves the entry half. It lets you declare the styles an element should transition from the moment it first renders. Before this, the browser had no "before" state for a newly inserted element, so transitions on first render simply did not run:
/* The dialog's normal, visible state */
.dialog {
opacity: 1;
transform: translateY(0) scale(1);
transition: opacity 0.3s ease, transform 0.3s ease;
}
/* Where the transition STARTS on first render */
@starting-style {
.dialog {
opacity: 0;
transform: translateY(12px) scale(0.96);
}
}When the dialog appears, the browser now animates from the @starting-style values to the declared values. Entry animation, zero JavaScript. This works for any newly rendered element: toasts, dropdowns, tooltips, and view transitions. When those transitions misbehave in a framework (back button snapping, morphs silently not firing), our view transition pitfalls guide has the debugging checklist.
3. Exit Animations with allow-discrete
Exit is the clever part. The trick has two halves. First, transition-behavior: allow-discrete tells the browser it may transition discrete properties like display and visibility. The discrete flip still happens instantly, but now it can be timed: it flips at the 50 percent mark for display, and at the very end for closing transitions on visibility. Second, you keep the visible styles on the element and define the closing state with a class, exactly like the entry pattern in reverse:
.popover {
opacity: 1;
transform: translateY(0);
transition:
opacity 0.25s ease,
transform 0.25s ease,
display 0.25s allow-discrete;
}
/* Closing state: applied via a class before hiding */
.popover.closing {
opacity: 0;
transform: translateY(8px);
}
/* Entry: where the open transition starts */
@starting-style {
.popover {
opacity: 0;
transform: translateY(8px);
}
}The flow: add the .closing class, wait for the transition to finish, then set display: none. Because the transition itself covers the discrete display flip, the popover fades out smoothly and only then leaves the render tree. A tiny transitionend listener or a setTimeout matching the duration handles the timing.
4. The Full Dialog Pattern, Copy-Paste Ready
Here is the complete pattern for a native dialog element, the most common real-world case. It handles entry, exit, and the backdrop:
dialog {
opacity: 1;
transform: translateY(0) scale(1);
transition:
opacity 0.3s ease,
transform 0.3s ease,
display 0.3s allow-discrete,
overlay 0.3s allow-discrete;
}
dialog::backdrop {
background: rgb(0 0 0 / 0.5);
opacity: 1;
transition:
opacity 0.3s ease,
display 0.3s allow-discrete,
overlay 0.3s allow-discrete;
}
/* Entry starting point */
@starting-style {
dialog {
opacity: 0;
transform: translateY(16px) scale(0.97);
}
dialog::backdrop {
opacity: 0;
}
}
/* Exit state */
dialog.closing,
dialog.closing::backdrop {
opacity: 0;
}The overlay property is the quiet hero here. It keeps the dialog in the top layer during the exit transition so the backdrop does not vanish mid-fade. Without it, top-layer elements can pop out of the layer before the animation finishes.
5. transition-behavior, Plainly Explained
The transition-behavior property accepts two values. normal is the default you have always known: discrete properties flip instantly with no transition. allow-discrete opts discrete properties into the transition. The flip still happens at a single instant, but you control when: for a closing transition the flip waits until the end, so your fade completes first. Think of it as scheduling the disappearance after the animation, declaratively.
6. Doing It in Tailwind CSS
Tailwind has no core utilities for these properties yet, but arbitrary properties cover the gap cleanly:
<div class="transition-all duration-300
[&:not(.closing)]:opacity-100
opacity-0 translate-y-2
[transition-behavior:allow-discrete]
starting:opacity-0 starting:translate-y-2">
<!-- popover content -->
</div>The starting: variant maps to @starting-style, and the arbitrary property sets transition-behavior. Toggle the closing class from your framework of choice and the same pure-CSS exit animation runs.
7. Browser Support and Fallbacks
@starting-style, transition-behavior: allow-discrete, and overlay are Baseline features, supported in all modern browsers since 2024. For older browsers, guard the enhancement with @supports so the animation is progressive, not required:
@supports (transition-behavior: allow-discrete) {
.popover {
transition:
opacity 0.25s ease,
transform 0.25s ease,
display 0.25s allow-discrete;
}
}Outside the @supports block, keep the plain show and hide logic. Users on older browsers get an instant toggle, which is a perfectly fine experience, while modern browsers get the smooth animation. Also respect prefers-reduced-motion: skip the transitions entirely for users who ask for reduced motion.
8. Frequently Asked Questions
Can you animate display: none in CSS?
Not the flip itself, since display has no intermediate values. But with transition-behavior: allow-discrete you can time the flip to happen after a fade or slide completes, which is the effect everyone actually wants.
What is @starting-style used for?
It defines the starting values for a transition on an element's first render. Without it, newly inserted elements have no "before" state, so entry transitions never run.
How do I animate an element being removed without JavaScript?
Apply a closing class that sets the end-state styles, let the transition run with allow-discrete covering display, then remove the element when the transition ends. The animation is pure CSS; only the timing of the removal needs a line of JavaScript.
What does the overlay property do?
It controls whether a top-layer element (dialogs, popovers) stays in the top layer. Transitioning it with allow-discrete keeps the element layered until a close animation finishes, preventing the backdrop from vanishing early.
Try it now: design your keyframes in the free CSS Animation Generator, then use the @starting-style and allow-discrete patterns above to give your dialogs and menus smooth exits as well as entries. For scroll-linked motion, see our scroll animations guide.
Staggered Entrances with transition-delay
@starting-style sets the from-state for every matched element, and transition-delay staggers them. The combination gives choreographed list entrances with no JavaScript:
.menu-item {
transition: opacity 0.25s ease, transform 0.25s ease;
}
.menu-item:nth-child(2) { transition-delay: 0.05s; }
.menu-item:nth-child(3) { transition-delay: 0.1s; }
.menu-item:nth-child(4) { transition-delay: 0.15s; }
@starting-style {
.menu-item { opacity: 0; transform: translateY(10px); }
}Each item still transitions from the same starting style; the delay only offsets when each one begins. Keep the total stagger under about 0.3 seconds. Longer than that and the menu feels laggy instead of polished. I cap stagger lists at four or five items; beyond that, animate the container and let the items come along for free.
The Page-Load Flash: @starting-style Fires on First Paint
@starting-style does not distinguish "the user opened the menu" from "the page just loaded." Any element matching the rule animates from the starting style on its very first render. For a dialog that starts hidden, nobody sees it. For a hero card or a sidebar present in the initial HTML, every page load replays the entrance animation, which reads as a bug.
The fix is to declare the transition only when animation is actually wanted. Ship the resting styles in the initial markup, and let JavaScript add the animating class after load:
/* resting state, no transition: first paint is instant */
.menu { opacity: 1; transform: none; }
/* animation styles, added by JS after load or on first open */
.menu.animate-in { transition: opacity 0.3s ease, transform 0.25s ease; }
@starting-style {
.menu.animate-in { opacity: 0; transform: translateY(12px); }
}Because the starting style is scoped to .animate-in, the initial server-rendered paint has no transition declared and renders instantly. Later toggles, when the element re-enters the render tree, animate from the starting style as intended.
Debugging: Why Your Transition Never Fires
When the animation silently does nothing, run this checklist before rewriting anything:
1. display must be listed in the transition property with allow-discrete. Without it, the visibility flip happens instantly and takes your fade with it.
2. transitionend fires once per transitioned property. A transition over opacity, transform, and display fires three events. Always check event.propertyName before running cleanup, or your removal logic runs three times.
3. Toggling a class off and on in the same frame gets batched by the browser and nothing animates. Force a reflow between the two changes (void element.offsetWidth) or split them across requestAnimationFrame calls.
4. Chrome DevTools has an Animations panel (More tools, Animations) that shows every running transition on a timeline. If your transition is not on the timeline, the browser never started it, which points at item 1 or 3.
Item 3 is the one that gets everyone. The code looks right, the classes are right, and the browser simply coalesced the change.