CSS propertyTransitions

transition-behavior

Lets you include properties that change discretely, such as display, in transitions.

Initial value
normal
Inherited
No
Animatable
no
Applies to
all elements
JavaScript
element.style.transitionBehavior = "allow-discrete"
On this page

Example

#
CSS
.popup {
  transition: opacity 0.3s, display 0.3s allow-discrete;
}

.popup.closed {
  opacity: 0;
  display: none;
}

@starting-style {
  .popup { opacity: 0; }
}
Preview

Definition and usage

#

Some properties, for example display or content-visibility, change discretely and by default do not take part in transitions. The allow-discrete value lets you include them in a transition.

This way an element can fade out smoothly through an opacity change, and display: none takes effect only at the end of the transition instead of hiding the element at once.

To make an element appear smoothly you also need the @starting-style rule, which describes the initial state right after the element is displayed.

Syntax

#
Syntax
transition-behavior: normal | allow-discrete;

Values

#
  • normal

    The element disappears immediately, because display changes at once.
  • allow-discrete

    The element fades out smoothly, and display: none applies at the end of the transition.

Values in practice

#

normal

The element disappears immediately, because display changes at once.
.demo { transition-behavior: normal; }

allow-discrete

The element fades out smoothly, and display: none applies at the end of the transition.
.demo { transition-behavior: allow-discrete; }

Browser support

#

Newly available Β· since 2024

Works in the current versions of all major browsers. Older versions may not support it.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • You can add the allow-discrete keyword to the transition shorthand for a specific property, as in the example.
  • To animate elements entering the page you also need @starting-style.

Related entries

#

Spotted a mistake or missing an example? Write to us.