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"
Example
#.popup {
transition: opacity 0.3s, display 0.3s allow-discrete;
}
.popup.closed {
opacity: 0;
display: none;
}
@starting-style {
.popup { opacity: 0; }
}<p style="margin: 0; color: #a3a3a3;">The popup smoothly appears and disappears, even though display is toggled.</p>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
#transition-behavior: normal | allow-discrete;Values
#- The element disappears immediately, because
displaychanges at once. - The element fades out smoothly, and
display: noneapplies at the end of the transition.
Values in practice
#normal
display changes at once..demo { transition-behavior: normal; }allow-discrete
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-discretekeyword to thetransitionshorthand for a specific property, as in the example. - To animate elements entering the page you also need
@starting-style.
Related entries
#- transitionA shorthand that makes CSS value changes happen smoothly instead of abruptly.
- transition-propertySpecifies which CSS properties should change smoothly.
- displayDetermines how an element behaves in the page layout and how it lays out its children.
- @starting-styleDescribes the style a transition starts from when an element appears on the page. This lets new elements slide in smoothly.
Spotted a mistake or missing an example? Write to us.