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.
.panel { transition: opacity 300ms, display 300ms allow-discrete; }
Try it
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
transition-behavior: <transition-behavior-value>#
<transition-behavior-value> = normal | allow-discrete
- Initial value:
normal - Applies to: all elements, and the
::beforeand::afterpseudo-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
displayis special. Whendisplaychanges to or fromnone, the browser uses the non-nonevalue for the whole transition, so the element stays visible while other properties animate. It flips tononeat the end, or fromnoneat the start.- Entering needs
@starting-style. An element coming fromdisplay: nonehas 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) andvisibility. - The shorthand. Add
allow-discreteas a keyword intransition, per entry:transition: display 300ms allow-discrete. - Remember to list the property.
transition-behavior: allow-discretedoes nothing unless the discrete property (orall) is intransition-propertyand has a duration. - Progressive enhancement. Without support, the element simply changes instantly, which is an acceptable fallback; feature-test with
@supportsorCSS.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.
Related
transitionโ the shorthandtransition-propertyโ which properties transition@starting-styleโ initial styles for first renderdisplayโ the most common discrete property- Lesson: Transitions