← Blog8 min read#discrete animation#css#display

Animating Discrete Properties in CSS: display, content-visibility

CSS can now animate display:none and content-visibility. Learn how discrete property transitions work, what @starting-style does, and how to ship real UI animations without JavaScript.

Abstract CSS code on a dark screen with animation curves

The Problem With display:none (Until Now)

For years, animating an element in and out of display:none meant either accepting an abrupt cut or dragging in a JavaScript library to toggle classes at just the right moment. There was no middle ground. The browser treated display as a discrete property - you flip it on or off, and there's nothing in between to interpolate.

That changed in Chrome 117 (2023) and has since shipped in Firefox 129 and Safari 18. The spec calls it transition behavior: allow-discrete, and it fundamentally changes how you think about enter/exit animations. Instead of fighting the cascade with visibility: hidden hacks or pointer-events: none workarounds, you can now transition display directly alongside opacity, transform, or whatever else you're animating.

In practice, this matters most for modal dialogs, tooltips, dropdown menus, and any component that needs to be truly removed from the layout when hidden - not just invisible. You've probably shipped a visibility + opacity combo before just to get pointer-events out of the way. That whole pattern is now unnecessary.

Worth noting: discrete properties don't interpolate the way opacity: 0 β†’ 1 does. Instead, the browser holds the outgoing value until the very end of the transition (on exit) or switches to the incoming value at the very start (on enter). That flip-at-boundary behavior is what makes the animation work - your opacity fade does the visual work while display holds steady until the last frame.

transition-behavior: allow-discrete - The Syntax

The new property is dead simple. Add transition-behavior: allow-discrete to any transition declaration that involves a discrete property, and the browser opts in to the new behavior. You can also use the allow-discrete keyword directly inside the shorthand transition property.

.modal {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 200ms ease,
    transform 200ms ease,
    display 200ms allow-discrete;
}

.modal.open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

When .open is added, display flips to block immediately (at the start of the transition), so opacity and transform have a visible element to animate on. When .open is removed, display stays block until the very last frame - opacity and transform finish fading out first, *then* the element vanishes. No JavaScript timers. No transitionend listeners.

That said, there's a catch on the enter side. The browser doesn't know what the "before" state of a newly-displayed element is, so it skips the opening animation by default. That's where @starting-style comes in.

Honestly, the shorthand syntax is what you'll use 95% of the time. The longhand transition-behavior property exists for cases where you need to stack multiple transitions and only some of them are discrete - you can set it selectively rather than rewriting the whole transition declaration.

@starting-style: Defining the "Before" State

@starting-style is a new at-rule that lets you describe the initial values an element should animate *from* when it first becomes visible. Without it, the browser has no before-state to interpolate from on entry - the element just pops in fully rendered.

.modal {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 200ms ease,
    transform 200ms ease,
    display 200ms allow-discrete;
}

.modal.open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  .modal.open {
    opacity: 0;
    transform: translateY(8px);
  }
}

The @starting-style block mirrors your hidden state. You're telling the browser: "when this element first matches .modal.open, treat these as the starting values before any transition runs." From there the normal transition takes over and eases to the final values.

Quick aside: @starting-style works independently of allow-discrete. You can use it to animate any property on first render - even on elements that were already in the DOM but just got a class added. It shipped alongside allow-discrete in Chromium but solves a subtly different problem.

One more thing - nesting @starting-style inside the rule it targets is also valid syntax and can keep things tidier in large stylesheets: ``css .modal.open { display: block; opacity: 1; transform: translateY(0); transition: opacity 200ms, transform 200ms, display 200ms allow-discrete; @starting-style { opacity: 0; transform: translateY(8px); } } ``

Animating content-visibility

content-visibility: hidden is the rendering-optimized sibling of display: none. It skips layout and paint for the element entirely, which makes it dramatically faster than opacity tricks for off-screen content. The browser can skip hundreds of milliseconds of render work on complex subtrees. On pages with lots of panels, tabs, or route sections, this adds up fast.

Like display, content-visibility is discrete - there's no "half hidden" state. But as of Chrome 124 and Firefox 133, it also supports allow-discrete transitions. The pattern is the same: ``css .panel { content-visibility: hidden; opacity: 0; transition: opacity 250ms ease, content-visibility 250ms allow-discrete; } .panel.visible { content-visibility: visible; opacity: 1; @starting-style { opacity: 0; } } ``

In practice, content-visibility is the better choice when you have heavy subtrees - think entire route panels, off-canvas sidebars, or anything with deeply nested components. display: none is fine for simple elements like tooltips and small dropdowns. The rendering skip that content-visibility: hidden gives you doesn't matter for a 48px tooltip, but it matters a lot for a 300-element data table that's just off-screen.

Look, you can't use both on the same element simultaneously in a meaningful way - they serve overlapping purposes. Pick content-visibility for layout-heavy hidden sections, display for small ephemeral UI pieces. The animation API for both is identical, which is a nice consistency win from the spec authors.

Real Component Example: Accessible Modal

Let's put this together into something you'd actually ship. A modal that's hidden from the accessibility tree when closed, animates in smoothly, and requires zero JavaScript for the animation itself - only JS for toggling the class and managing focus. ``css /* modal.css */ .modal-backdrop { position: fixed; inset: 0; display: none; background: hsl(0 0% 0% / 0.5); backdrop-filter: blur(4px); opacity: 0; transition: opacity 200ms ease, display 200ms allow-discrete; } .modal-box { position: fixed; inset: 50% auto auto 50%; translate: -50% -50%; display: none; opacity: 0; transform: scale(0.95); transition: opacity 250ms ease, transform 250ms ease, display 250ms allow-discrete; } .modal-backdrop.open, .modal-box.open { display: block; opacity: 1; } .modal-box.open { transform: scale(1); } @starting-style { .modal-backdrop.open { opacity: 0; } .modal-box.open { opacity: 0; transform: scale(0.95); } } ``

The JavaScript side stays minimal - you're just toggling .open on both elements. The enter animation runs automatically because of @starting-style, and the exit animation holds both elements visible until their transitions finish before display: none kicks in.

For the glassmorphism components crowd: the backdrop backdrop-filter: blur(4px) also transitions correctly here because you can add it to the transition list normally - it's not a discrete property. Pair that with a frosted modal box and you get a polished effect with maybe 30 lines of CSS. Check the glassmorphism generator if you want to dial in the blur and transparency values.

Worth noting: you still need aria-modal, role="dialog", and proper focus management in JS. allow-discrete doesn't change any accessibility behavior - it only handles the visual transition. An element with display: none is still hidden from screen readers when the modal is closed, which is exactly what you want.

The popover API and Native Dialog

The native <dialog> element and the Popover API (both now baseline) already handle some of this automatically in supporting browsers. When you call dialog.showModal() or toggle a popover, the browser runs entry/exit animations defined on ::backdrop and the element itself - and allow-discrete is already baked into how these work internally.

/* Animating native <dialog> */
dialog {
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 200ms, transform 200ms,
    display 200ms allow-discrete,
    overlay 200ms allow-discrete; /* overlay is also discrete */
}

dialog[open] {
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  dialog[open] {
    opacity: 0;
    transform: translateY(-12px);
  }
}

Notice overlay 200ms allow-discrete in there. overlay is a new CSS property that controls whether an element is in the "top layer" - the special browser rendering layer used by modals, popovers, and fullscreen elements. Without transitioning overlay, the dialog drops out of the top layer immediately on close, cutting off the exit animation. It's a discrete property, so it needs allow-discrete too.

This is also where things get genuinely interesting for component libraries. If you're building an Empire UI-style component system where every element has polished motion, the combination of <dialog>, popover, @starting-style, and allow-discrete gets you very far before you ever need Framer Motion or GSAP. Not a dig at those tools - for complex choreography they're still the right call - but for standard show/hide patterns, the platform has finally caught up.

Browser Support and Progressive Enhancement

As of mid-2026, transition-behavior: allow-discrete is supported in Chrome 117+, Firefox 129+, and Safari 18+. That covers around 92% of global users according to caniuse data. The remaining 8% is mostly older Safari on iOS, where elements will still show/hide - they just won't animate. That's a perfectly acceptable fallback.

You don't need a feature query for most use cases. Without allow-discrete support, the browser simply ignores the keyword and falls back to an instant show/hide - your opacity and transform transitions may or may not run depending on how the browser handles the malformed transition value. To be safe with older Safari, wrap the animated version: ``css /* Base: instant show/hide, works everywhere */ .dropdown { display: none; } .dropdown.open { display: block; } /* Enhanced: smooth animation where supported */ @supports (transition-behavior: allow-discrete) { .dropdown { opacity: 0; transition: opacity 200ms, display 200ms allow-discrete; } .dropdown.open { opacity: 1; } @starting-style { .dropdown.open { opacity: 0; } } } ``

Honestly, the @supports wrapper is optional for most production apps targeting modern browsers. Ship the allow-discrete version directly and let older browsers degrade gracefully - the worst case is a snap cut, which is exactly what everyone was doing before 2023 anyway.

If you're exploring more CSS animation techniques, css-starting-style goes deeper on @starting-style alone, and css-view-transitions covers the sibling spec for full-page animation. Both pair well with what you've learned here. And if you want to see how these animations look applied to real component patterns, browse the components at Empire UI to see discrete transitions used in dropdowns, modals, and notification components.

FAQ

Does allow-discrete work with CSS animations (@keyframes), or only transitions?

Only transitions for now. @keyframes with display or content-visibility doesn't use allow-discrete - the discrete flip still happens at 50% of the animation duration by default. Use transitions for controlled enter/exit patterns.

Do I need @starting-style for the exit animation?

No. @starting-style only affects the enter animation. The exit works automatically because allow-discrete holds the display: block value until the transition finishes, then snaps to none.

Can I transition content-visibility and display on the same element?

Technically yes, but there's no practical reason to. They serve the same purpose - hiding an element from layout and rendering. Pick one based on your use case and stick with it.

What's the difference between transitioning overlay and display?

overlay controls whether the element stays in the browser's top layer during its exit transition - critical for native <dialog> and popover elements. display controls whether the element is in the regular document flow. You usually need both for top-layer elements.

Free components in 41 styles
React & Tailwind, copy-paste ready.
Browse β†’

Read next

CSS Animations & Motion Design: The Complete 2026 Playbook β†’CSS @starting-style: Entry Animations Without JS Classes β†’CSS Houdini Paint Worklet: Custom CSS Properties With GPU Power β†’What Is Glassmorphism? A Free React + Tailwind Guide β†’