---
title: "Why is my CSS transition not working?"
description: "Transitions fail silently when a property can't animate, such as display: none or height: auto. Learn the common causes and the modern fixes, including allow-discrete."
url: https://www.danny.engineering/answer/css/why-is-my-css-transition-not-working
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["CSS"]
---

# Why is my CSS transition not working?

## The short answer


A transition needs a start value and an end value the browser can interpolate between. It will not run if the property is `display`, if one side is `height: auto`, or if the element has just been added to the page. Animate `opacity` and `transform` instead, or use `transition-behavior: allow-discrete` with `@starting-style` for elements that appear and disappear.


```css
.panel {
  opacity: 1;
  transition: opacity 200ms, display 200ms allow-discrete;
}

.panel[hidden] {
  display: none;
  opacity: 0;
}

@starting-style {
  .panel {
    opacity: 0;
  }
}
```


## Why it happens


A CSS transition runs when a property's computed value changes from one value to another. The browser then draws the in-between values over the duration you set. That only works when:

- The property is animatable and both values are of a type that can be mixed, such as two lengths or two colours.
- The element already had a computed style before the change. A newly inserted element has no "before", so it just appears in its final state.
- The `transition` declaration applies to the state the element is moving into, or to both states.

`display` is a discrete property: there is no halfway point between `block` and `none`. When it flips to `none`, the element is removed from rendering immediately, so any opacity fade alongside it is cut off. Keywords such as `auto`, `min-content` and `fit-content` are not numbers either, so `height: 0` to `height: auto` cannot be interpolated by default.


## How to fix it


### Transition entry and exit with allow-discrete


`transition-behavior: allow-discrete` (or the `allow-discrete` keyword in the shorthand) lets discrete properties like `display` take part. The browser keeps the element visible for the length of the exit transition and only switches `display` at the end. `@starting-style` gives an element its "before" values the first time it renders, so the entry animates too. Both are supported in current Chrome, Edge, Firefox and Safari, and have been since 2024.


This pattern works well for popovers and dialogs, which move in and out of the top layer:


```css
[popover] {
  opacity: 0;
  transition:
    opacity 200ms,
    overlay 200ms allow-discrete,
    display 200ms allow-discrete;
}

[popover]:popover-open {
  opacity: 1;
}

@starting-style {
  [popover]:popover-open {
    opacity: 0;
  }
}
```


In older browsers the element simply appears and disappears without animation, which is a safe fallback.


### Animate to height: auto


`interpolate-size: allow-keywords` lets the browser transition between a length and a sizing keyword like `auto`. Set it on `:root` to opt in for the whole page. At the time of writing it is only supported in Chromium browsers (Chrome and Edge), so treat it as an enhancement: other browsers jump straight to the end state.


```css
:root {
  interpolate-size: allow-keywords;
}

.drawer {
  height: 0;
  overflow: hidden;
  transition: height 300ms ease;
}

.drawer.is-open {
  height: auto;
}
```


For a cross-browser approach today, animate a grid track from `0fr` to `1fr`. Grid tracks interpolate in every modern browser.


```css
.drawer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms ease;
}

.drawer.is-open {
  grid-template-rows: 1fr;
}

.drawer > .inner {
  overflow: hidden;
}
```


### Wait a frame for elements added with JavaScript


If you insert an element and add a class in the same task, the browser never sees the starting style. Use `@starting-style` where you can. Otherwise, force a style calculation or wait for the next frame before adding the class.


```javascript
list.append(item);
requestAnimationFrame(() => {
  item.classList.add('is-visible');
});
```


### Check that the transition rule applies


Open DevTools, select the element and look at the computed `transition` value in both states. A more specific rule, a utility class or a framework reset may be overriding it, or the transition may only be declared on the hover state, so it plays one way but not back.


## Common pitfalls

- Transitioning `all`. It is easy to animate properties you did not mean to, and it hides which property is really changing. List the properties.
- Misspelling a property or unit in the shorthand. An invalid `transition` value is dropped completely, with no error.
- Animating `width`, `height` or `top` for movement. They trigger layout on every frame. `transform` and `opacity` are much cheaper.
- Forgetting users who prefer less motion. Wrap large movement in `@media (prefers-reduced-motion: no-preference)`.
- Putting `allow-discrete` on the whole shorthand with `all`. Be explicit about which properties are discrete.

## Related reading

- [MDN: transition-behavior](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior)
- [MDN: @starting-style](https://developer.mozilla.org/en-US/docs/Web/CSS/@starting-style)
- [MDN: interpolate-size](https://developer.mozilla.org/en-US/docs/Web/CSS/interpolate-size)
