Menu

Animate display: none in Pure CSS! Modern @starting-style & allow-discrete Explained
πŸ“°

Animate display: none in Pure CSS! Modern @starting-style & allow-discrete Explained

DEV Community: cssΒ·Muneeb AliΒ·3 days ago
#9ldVrRYP
#devtocss#devto#dev#display#opacity
Reading 0:00
15s threshold

For over 10 years, transitioning elements from display: none was considered impossible in pure CSS without JavaScript reflow workarounds like requestAnimationFrame or void element.offsetWidth .

Those days are officially over! Modern CSS introduces two game-changing features (Baseline 2024 across Chrome, Safari, and Firefox):

@starting-style : Defines the before-change style snapshot at frame 0 when an element transitions from display: none or mounts to the DOM.

transition-behavior: allow-discrete : Delays flipping to display: none until your exit transitions finish completely.

πŸ’‘ The Mental Model: The Broadway Stage Analogy

To understand why this is necessary, think of a browser render engine like a Broadway theater:

Without @starting-style : Toggling display: none to display: block is like an actor suddenly teleporting from backstage straight into a 100% bright spotlight.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.