# Fading out of display: none

Source: https://websgeek.com/css-transition-display-none
Publisher: WebsGeek (https://websgeek.com), updated 2026-11-22

By the end you will know why display: none cuts off a CSS fade, and how allow-discrete, @starting-style and the right declaration order let an element fade both in and out.

## Why the fade never plays

A CSS transition cannot fade an element out to `display: none` on its own, because `display` is a discrete property. By default it switches the moment the style changes, so the element is gone before `opacity` can draw a single frame. The fix takes two additions. `transition-behavior: allow-discrete` keeps the element displayed until the exit ends, and `@starting-style` gives the entry a first frame to fade from.

Both cards below get the same opacity and movement transition. The left one uses only that. The right one adds the two fixes. Press the button a few times and watch both directions.

> Interactive demo: Same fade, two outcomes (try it on the page).

The left card snaps in both directions. The right card fades out and fades in. The readout does not guess: after each click it asks the browser whether the card has any transitions running. The rest of this guide adds the fixes one at a time. Along the way it covers the declaration-order mistake that quietly cancels the first one.

## Discrete means no in-between

To transition a property, the browser has to **interpolate** it. That means working out the values between the start and the end. Opacity halfway between 1 and 0 is 0.5. Nothing sits halfway between `block` and `none`, so `display` is called a discrete property. With the default `transition-behavior: normal`, the browser does not transition discrete properties at all. It applies the new value right away.

The scrubber below shows what the browser works out at each moment of a 600 ms exit, with linear easing so the numbers are easy to follow. Drag it, or press Play. Then turn the switch off and drag again.

> Interactive demo: Step through an exit (try it on the page).

With the switch off, `display` is `none` from the very first frame. Opacity has a target of 0, but no box is left to paint it on. With the switch on, `display` stays `block` for the whole fade and flips only on the final frame.

That final-frame flip is a special rule. With `allow-discrete`, most discrete properties flip at the halfway point of the transition. `display` and `content-visibility` work differently. When one side of the change is `none` (or `hidden` for `content-visibility`), the browser keeps the visible value for the whole duration. On exit, the flip lands at the end. On entry, it lands at the start.

**One level deeper.** Transitions start during a *style change event*. The browser compares each element's style before the change with its style after it. For every listed property that changed and can be interpolated, it creates a transition. A `display: none` element has no box, so the browser cancels any transitions running on it. So the snap is not your opacity transition failing. It never got a chance to start.

## Keep display alive for the exit

The first fix has two parts. Add `display` to the transition list. Then set `transition-behavior: allow-discrete`, which tells the browser that discrete properties in the list may transition too. The card now stays displayed until its opacity reaches zero.

> Interactive demo: Turn allow-discrete on and off (try it on the page).

With the switch off, the exit snaps in one frame. Turn it on and the readout shows how long the fade took, measured from the click until the browser reports that every transition has finished. Now show the card with the switch off. **The entry still fades.** On entry the element has to appear right away anyway, so `allow-discrete` is only needed for the exit. The entry fades for a different reason, which the next section covers.

**Put display in the list and allow it to transition.**

```
.card {
  transition: opacity .3s, transform .3s, display .3s;
  transition-behavior: allow-discrete;
}

.card[hidden] {
  display: none;
  opacity: 0;
  transform: translateY(10px);
}
```

The explicit `display: none` on `[hidden]` is deliberate. The browser's own `[hidden]` rule loses to any `display` value you set on `.card`. If you later make the card a flex container, the hidden attribute would stop hiding it without that line.

## Give the entry a first frame

An element coming back from `display: none` has no previous style. The browser has nothing to compare against, so it treats the visible style as the only style, and there is nothing to transition from. `@starting-style` supplies that missing "before" value. In the demo below, it starts switched off.

> Interactive demo: Turn @starting-style on and off (try it on the page).

Hide the card and it fades out, because `allow-discrete` is already on. Show it and it pops in. Turn on `@starting-style` and the entry fades too. The exit never needed it.

**The entry starts from the @starting-style values.**

```
.card {
  opacity: 1;
  transform: none;
  transition: opacity .3s, transform .3s, display .3s;
  transition-behavior: allow-discrete;
}

/* Same specificity as .card, so it must come after it */
@starting-style {
  .card {
    opacity: 0;
    transform: translateY(10px);
  }
}
```

**One level deeper.** `@starting-style` rules apply only during an element's first style update. That happens when the element goes from `display: none` to visible, or when it is first added to the document. The browser uses those values as the "before" style, then applies the real style, and the difference becomes a normal transition. The rules cascade like any other rules. A `@starting-style` block with the same specificity placed above `.card` loses, and the entry snaps without any warning. Nesting the block inside the `.card` rule keeps the two together, but order still counts there. Put the nested `@starting-style` after the declarations in the rule. In current browsers, declarations written after a nested rule come later in the cascade and win over it.

## The shorthand that undoes it

This is the bug that sends most people searching. You add `transition-behavior: allow-discrete` and it does nothing. Usually a `transition` shorthand comes after it, in the same rule or in a later rule that wins the cascade.

Both lanes below contain the same two declarations. Only the order differs. The note under the button shows the computed `transition-behavior` of each card, read from `getComputedStyle` in your browser. The readout below it reports what each card did.

> Interactive demo: Same declarations, different order (try it on the page).

`transition` is a shorthand, and `transition-behavior` is one of its longhands. A shorthand sets every longhand it covers, and any value you leave out goes back to its initial value. The initial value of `transition-behavior` is `normal`. So the left lane sets `allow-discrete`, and the shorthand one line later puts it back to `normal`. The left card snaps. The browser reports no error, because both declarations are valid.

**Put the longhand after the shorthand.**

```
/* Broken: the shorthand resets transition-behavior to normal */
.card {
  transition-behavior: allow-discrete;
  transition: opacity .3s, display .3s;
}

/* Works: the longhand comes last */
.card {
  transition: opacity .3s, display .3s;
  transition-behavior: allow-discrete;
}

/* Also works, but older browsers drop the whole line */
.card { transition: opacity .3s, display .3s allow-discrete; }
```

The same reset happens across rules. Suppose a modifier such as `.card.is-urgent` sets a new `transition` shorthand. It removes `allow-discrete` for that variant only, which makes the bug look random. Putting `allow-discrete` inside the shorthand avoids the problem in current browsers. Browsers that do not know the keyword, though, throw away the entire declaration, and your opacity fade goes with it. A separate longhand after the shorthand is the safer habit.

## Remove it after it leaves

Calling `element.remove()` gives you no exit at all. Transitions only run on elements that are in the document. To dismiss something for good, hide it first, wait for its transitions to finish, then remove it.

> Interactive demo: Dismiss the notifications (try it on the page).

Each notification fades out, then leaves the DOM. The readout shows how long after your click that happened. Press **Bring them back** and the new nodes fade in, because `@starting-style` also covers an element's first appearance in the document. With the keyboard, focus moves to the next Dismiss button, so you never end up on an element that is about to disappear.

**Make it inert, hide it, wait for every transition, then remove.**

```
async function dismiss(item) {
  item.inert = true; // no clicks, focus or AT access during the fade
  item.hidden = true;
  const running = item.getAnimations().map(a => a.finished);
  await Promise.allSettled(running);
  item.remove();
}
```

`getAnimations()` returns the CSS transitions that the style change just started, including the one on `display`. Waiting on all of them works better than listening for `transitionend`. That event fires once for each property, and a canceled transition never sends it at all. If nothing is running, the list is empty and the item is removed immediately.

During the fade the element is still displayed, so a mouse or a finger can still click it. Moving focus away does not prevent that. Set the `inert` attribute for the duration of the fade, as the sample and this demo do. An inert element ignores pointer input, drops out of the tab order and is hidden from the accessibility tree. Move focus first, then set `inert`, so focus does not fall back to the page body. If you cannot use `inert`, a `pointer-events: none` rule on `[hidden]` at least blocks pointer clicks.

The other siblings close the gap instantly once the item is gone. Animating that space is a height problem, which [accordions without the jump](https://websgeek.com/accordions-without-the-jump) covers.

## Ship it with a fallback

Chrome and Edge support both `allow-discrete` and `@starting-style` from version 117. Safari supports `transition-behavior` from 17.4 and `@starting-style` from 17.5. Firefox has supported both since version 129, so entry fades work there. The exit is different. Firefox release notes have not announced `display` exit transitions, and Mozilla's tracking bug for them, bug 1882408, is still open. In current Firefox the element still disappears at once. `CSS.supports()` reports support all the same, so test for the behavior instead of the syntax. The panel below runs that check in your browser and picks a path.

> Interactive demo: Detect the behavior, then pick a path (try it on the page).

The native path only sets `hidden`. The fallback first sets a closing attribute that fades the card out, waits for that fade to finish, and only then sets `hidden`. Both paths make the card inert while it fades. Turn on **Force the fallback** to see that both paths look the same. The entry uses `@starting-style` either way.

**Probe whether display is really held during an exit.**

```
function holdsDisplay() {
  const el = document.createElement('div');
  el.style.transition = 'display 1s';
  el.style.transitionBehavior = 'allow-discrete';
  document.body.append(el);
  getComputedStyle(el).display; // commit the "before" style
  el.style.display = 'none';
  const held = getComputedStyle(el).display !== 'none';
  el.remove();
  return held;
}
```

For people who set `prefers-reduced-motion: reduce`, keep the opacity fade short and drop the movement. Every demo in this guide sets its slide distance to zero when that preference is on. A fade does not move anything across the screen, so it still shows that the element appeared or left. For a `<dialog>` or a popover, also add `overlay` to the transition list with `allow-discrete`, so the element stays in the top layer until the fade ends. Check browser support for `overlay` separately.

> **When to use it.** Use it for things you show and hide with `hidden` or `display`: menus, popovers, notifications, and confirmations like the ones in [a save you can see land](https://websgeek.com/a-save-you-can-see-land). Skip it when the element should keep its space while invisible. Use `opacity` with `visibility` for that. Skip it when you need to animate height. And skip it when an exit must look the same in every browser today. In that case use the fallback path for everyone.**Keep reading:** [why a transition doesn't run when a class is added](https://websgeek.com/css-transition-not-working-class-added) · [choosing an easing curve for the fade](https://websgeek.com/easing-functions-visualization)

## Quick answers

**Why doesn't my CSS transition work with display: none?**
Display is a discrete property, so there is no value between block and none. With the default transition-behavior: normal, the browser applies display: none right away. The element loses its box, and any transitions running on it are canceled, so your opacity fade never starts. Add display to the transition list and set transition-behavior: allow-discrete to keep the element displayed until the fade ends.

**Why is transition-behavior: allow-discrete not working?**
Usually a transition shorthand comes after it, either in the same rule or in a later rule that wins the cascade. A shorthand resets every longhand it covers, so transition-behavior goes back to its initial value, normal. The browser shows no error because both declarations are valid. Put transition-behavior: allow-discrete after the shorthand, and check modifier classes that set their own transition.

**How do I fade an element in from display: none?**
Use @starting-style. An element coming back from display: none has no previous style, so the browser has nothing to transition from. A @starting-style block gives it starting values, such as opacity: 0, for its first style update. The block cascades like any other rule, so place it after the main rule or nest it inside that rule. Otherwise the entry snaps.

**Which browsers support allow-discrete and @starting-style?**
Chrome and Edge 117 and later, and Safari 17.5 and later, support both. Firefox supports @starting-style and parses allow-discrete, but it has been slower to keep display alive during an exit. That means CSS.supports() can report support while the exit still snaps. Test whether display is really held during a transition, and use a script-driven fade when it is not.

**How do I fade out an element before removing it from the DOM?**
Calling element.remove() gives you no exit, because transitions only run on elements that are in the document. Set hidden first. Then wait for the finished promise of every animation from element.getAnimations() with Promise.allSettled, and remove the element after that. This is more reliable than transitionend, which fires once per property and never fires for a canceled transition.

---
This is the text version of "Fading out of display: none" from WebsGeek. The original page has live, interactive demos: https://websgeek.com/css-transition-display-none
When you use or quote this, cite: Fading out of display: none, WebsGeek, https://websgeek.com/css-transition-display-none
