Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The transition-behavior property

Reference for the CSS transition-behavior property: let discrete properties such as display transition with allow-discrete, with syntax, examples and support.

Some CSS properties cannot be blended smoothly. display is either none or block; there is nothing in between. These are called discrete properties. Normally a transition simply ignores them, and they change instantly.

The transition-behavior property can opt in to transitioning them. With allow-discrete, a discrete property still flips (usually at the halfway point), but the flip is timed by the transition, which lets other properties such as opacity finish animating before an element is removed from rendering with display: none.

CSS
.panel {
  transition:
    opacity 300ms,
    display 300ms allow-discrete;
}

Try it

Fade out, then display: none

Without allow-discrete on display, the panel would vanish instantly because display: none would be applied at the start of the transition. With it, the browser keeps the panel rendered until the opacity transition has finished. The @starting-style rule gives the panel a start value when it appears again, so the entry also fades in.

Syntax

CSS
transition-behavior: <transition-behavior-value>#

<transition-behavior-value> = normal | allow-discrete
  • Initial value: normal
  • Applies to: all elements, and the ::before and ::after pseudo-elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
normal Only properties that can be interpolated transition. Discrete properties change instantly.
allow-discrete Discrete properties transition too: their value flips at the 50% point of the transition, with some exceptions below.
Comma-separated list One value per property in transition-property.

Usage notes

  • display is special. When display changes to or from none, the browser uses the non-none value for the whole transition, so the element stays visible while other properties animate. It flips to none at the end, or from none at the start.
  • Entering needs @starting-style. An element coming from display: none has no previous style to animate from. Declare the start values in @starting-style.
  • Other useful discrete properties include content-visibility, overlay (for popovers and dialogs in the top layer) and visibility.
  • The shorthand. Add allow-discrete as a keyword in transition, per entry: transition: display 300ms allow-discrete.
  • Remember to list the property. transition-behavior: allow-discrete does nothing unless the discrete property (or all) is in transition-property and has a duration.
  • Progressive enhancement. Without support, the element simply changes instantly, which is an acceptable fallback; feature-test with @supports or CSS.supports() if you need to branch.

Browser support

This property and the animation of display are newer features. They are available in current versions of the major browsers, but check a compatibility table before depending on them for older browsers.