CSS Entry and Exit Transitions with @starting-style and Discrete Properties
Animate elements that appear or disappear with CSS while keeping their display and top-layer lifetimes correct.
CSS transitions normally need a previous rendered style to interpolate from. The @starting-style at-rule supplies an initial state for newly displayed elements, while transition-behavior: allow-discrete enables discrete changes such as display to participate in entry and exit transitions.
THE PRODUCTION PROBLEM STATEMENT
A popover that changes from display:none to visible has no prior rendered frame for a standard transition. Even when opacity animates in, the element can disappear immediately on close unless its display and top-layer state are retained through the exit.
Define a starting state for first display
Set the visible style in the normal open selector, then set the initial opacity and transform in @starting-style. The starting rule is used when the element first becomes rendered, including a transition out of display:none.
Keep the base closed state explicit. The transition needs a closed state, an entry state, and an open state to describe both directions.
.panel[popover] {
opacity: 0;
transform: translateY(-0.25rem);
transition: opacity 180ms, transform 180ms,
display 180ms allow-discrete,
overlay 180ms allow-discrete;
}
.panel[popover]:popover-open {
opacity: 1;
transform: translateY(0);
}
@starting-style {
.panel[popover]:popover-open {
opacity: 0;
transform: translateY(-0.25rem);
}
}Understand discrete display and overlay transitions
Display and overlay do not interpolate like opacity. The allow-discrete behavior tells the browser how to switch discrete values while the continuous properties animate. For top-layer elements, delaying overlay removal can keep the element available through its closing transition.
Verify the browser versions you support. A feature check or a non-animated fallback is safer than assuming support based on one browser.
Keep reduced motion and state changes in scope
Use short transitions and respect prefers-reduced-motion. Do not depend on an animation finishing to save application data or perform cleanup; visual transitions may be interrupted by navigation, a tab closing, or a change in user preference.
Avoid animating large page regions or layout-heavy properties. Entry and exit motion works best as a small cue for a panel whose functional state is already correct.
Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
A transition needs a starting value. A newly rendered element has no earlier rendered style, so @starting-style supplies one for the first transition.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Mastering Core Web Vitals: Engineering for Sub-100ms INP and Optimal LCP
A technical blueprint for diagnosing Interaction to Next Paint bottlenecks, accelerating Largest Contentful Paint, and maintaining zero Cumulative Layout Shift in production.
Mastering CSS Subgrid: Perfect Card Alignment and Fluid Multi-Column Form Layouts
How subgrid solves the historical card height mismatch, flushes CTA buttons, and creates synchronized multi-column forms without JavaScript.