CSS transition-behavior Property

The CSS transition-behavior property determines whether CSS properties with discrete animation behavior are allowed to participate in transitions.

By default, transitions involving discrete properties do not run. Setting transition-behavior: allow-discrete permits eligible discrete transitions, including changes to properties such as display and content-visibility. These properties switch between values at specific points rather than interpolating continuously.

transition-behavior Syntax

The transition-behavior property accepts the keywords normal and allow-discrete. Multiple values can be provided as a comma-separated list to correspond with multiple transitions.

Basic Syntax

.example {
  transition-behavior: allow-discrete;
}

Available Values

.example {
  transition-behavior: normal;
}
.example {
  transition-behavior: allow-discrete;
}

Multiple Values

.example {
  transition-behavior: normal, allow-discrete;
}

CSS-Wide Keywords

.example {
  transition-behavior: initial;
}
.example {
  transition-behavior: inherit;
}
.example {
  transition-behavior: unset;
}
.example {
  transition-behavior: revert;
}
.example {
  transition-behavior: revert-layer;
}

Invalid Examples

.example {
  transition-behavior: discrete;
}
.example {
  transition-behavior: smooth;
}
.example {
  transition-behavior: allow;
}
.example {
  transition-behavior: normal allow-discrete;
}

Only the defined keywords are valid. Multiple transition behavior values must be separated by commas.

Property Values

Value Description
normal Uses the default transition behavior. Properties with discrete animation behavior are not permitted to start transitions solely through this setting.
allow-discrete Allows eligible properties with discrete animation behavior to participate in transitions.

Property Characteristics

Characteristic Value
Initial value normal
Inherited No
Applies to All elements, including ::before and ::after
Computed value As specified
Animation type Not animatable
Percentages Not accepted
Specification CSS Transitions Level 2

Note: The transition-behavior property is a longhand component of the transition shorthand. It does not specify which properties transition or how long transitions last.

How It Works

CSS properties have different animation types. Some properties interpolate between values, while others use discrete changes.

Step 1: Define a Property Change

.panel {
  display: block;
}
.panel.is-hidden {
  display: none;
}

The display property changes between two discrete values.

Step 2: Add a Transition

.panel {
  transition: display 0.3s;
}

With the default transition behavior, this declaration does not enable a transition for the discrete display property.

Step 3: Allow Discrete Transitions

.panel {
  transition: display 0.3s;
  transition-behavior: allow-discrete;
}

Step 4: Combine With Opacity

.panel {
  opacity: 1;
  display: block;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  opacity: 0;
  display: none;
}

When the panel exits, opacity can fade toward zero while display remains visible until the end of the transition.

Step 5: Handle Entry Transitions

When an element changes from display: none to a rendered state, an entry transition typically requires @starting-style to establish the starting values.

Understanding the Result

The allow-discrete value permits the discrete property change to participate in the transition timeline. It does not create intermediate values between none and block.

The normal Value

The normal value is the default. It prevents properties with discrete animation behavior from starting transitions under the standard transition rules.

Basic Example

.example {
  transition-behavior: normal;
}

Transitioning Opacity

.example {
  transition: opacity 0.3s ease;
  transition-behavior: normal;
}

Opacity can interpolate continuously, so normal does not prevent its transition.

Attempting a display Transition

.example {
  transition: display 0.3s;
  transition-behavior: normal;
}

The discrete display change does not receive a transition through this declaration.

When to Use normal

Use normal when only ordinarily transitionable property changes should run and discrete property transitions are unnecessary.

Important Consideration

The normal value does not disable CSS transitions generally. It controls whether discrete animation behavior is permitted.

The allow-discrete Value

The allow-discrete value permits eligible properties with discrete animation behavior to participate in transitions.

Basic Example

.example {
  transition-behavior: allow-discrete;
}

Transitioning display

.panel {
  transition: display 0.3s;
  transition-behavior: allow-discrete;
}

Transitioning Multiple Properties

.panel {
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}

Using a Comma-Separated List

.panel {
  transition-property: opacity, display;
  transition-duration: 0.3s;
  transition-behavior: normal, allow-discrete;
}

Using all

.panel {
  transition: all 0.3s ease allow-discrete;
}

This permits eligible discrete transitions among all changing properties, but does not guarantee that every property can transition.

When to Use allow-discrete

Use this value when transitions need to coordinate discrete property changes with interpolated effects such as opacity or transforms.

Important Consideration

The property must still be eligible for a transition, and the browser must support the relevant discrete transition behavior.

Understanding Discrete Transitions

Discrete transitions differ from transitions that interpolate between numeric or color values.

Interpolated Transition

.box {
  opacity: 1;
  transition: opacity 0.4s ease;
}
.box.is-hidden {
  opacity: 0;
}

The opacity progresses through intermediate values between 1 and 0.

Discrete Transition

.box {
  visibility: visible;
  transition: visibility 0.4s allow-discrete;
}
.box.is-hidden {
  visibility: hidden;
}

The visibility property uses special visibility interpolation behavior. It remains visible during the applicable portion of the transition rather than fading through intermediate visibility values.

General Discrete Switching

Most discrete transitions switch values at the midpoint of the transition. For example, a transition lasting 0.4 seconds typically switches at 0.2 seconds.

Special Visibility Behavior

Properties such as display and content-visibility have special switching rules when transitioning between visible and non-visible states.

Entering a Visible State

When transitioning from display: none to a rendered display value, the switch to the rendered state occurs at the beginning of the transition.

Leaving a Visible State

When transitioning from a rendered display value to display: none, the switch to none occurs at the end of the transition.

Why This Matters

The special switching behavior allows effects such as opacity fades to remain visible while an element enters or leaves the rendered page.

Important Distinction

The allow-discrete keyword permits the transition. The individual property's animation type determines how its values change during that transition.

Transitioning display

The display property is a common use case for transition-behavior: allow-discrete.

Basic display Transition

.panel {
  display: block;
  transition: display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
}

Combining display and Opacity

.panel {
  display: block;
  opacity: 1;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
  opacity: 0;
}

Exit Behavior

When the panel changes from display: block to display: none, the browser can keep it rendered during the opacity fade and apply display: none at the end.

Entry Behavior

When the panel changes from display: none to display: block, the browser switches to the rendered state at the beginning. To animate opacity from zero during entry, use @starting-style.

Entry Starting Style

@starting-style {
  .panel:not(.is-hidden) {
    opacity: 0;
  }
}

Important Consideration

A display transition does not interpolate through intermediate display values. The special switching behavior coordinates the discrete change with other transitions.

Transitioning content-visibility

The content-visibility property controls whether an element's contents are rendered or skipped during rendering.

Basic Example

.panel {
  content-visibility: visible;
  transition: content-visibility 0.3s allow-discrete;
}
.panel.is-hidden {
  content-visibility: hidden;
}

Combining With Opacity

.panel {
  opacity: 1;
  content-visibility: visible;
  transition: opacity 0.3s ease, content-visibility 0.3s allow-discrete;
}
.panel.is-hidden {
  opacity: 0;
  content-visibility: hidden;
}

Entering the Visible State

When transitioning to content-visibility: visible, the browser makes the contents visible at the beginning of the transition.

Leaving the Visible State

When transitioning to content-visibility: hidden, the browser can keep the contents visible until the transition ends.

Difference From display

The display: none value removes an element's box from layout. The content-visibility: hidden value skips rendering its contents while retaining the element's principal box.

Important Consideration

Use the property that matches the desired layout and rendering behavior. The two properties are not interchangeable.

Working With @starting-style

The CSS @starting-style at-rule defines starting values for transitions when an element receives its first rendered style or returns from a non-rendered state.

Basic Entry Transition

.panel {
  opacity: 1;
  transition: opacity 0.3s ease;
}
@starting-style {
  .panel {
    opacity: 0;
  }
}

Entry With display

.panel {
  display: block;
  opacity: 1;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
  opacity: 0;
}
@starting-style {
  .panel:not(.is-hidden) {
    opacity: 0;
  }
}

Why @starting-style Is Needed

Ordinary CSS transitions generally require an established before-change style. Elements that were not rendered may not have one available for the entry transition.

How It Works With allow-discrete

The allow-discrete value permits the display transition. The @starting-style rule supplies an opacity starting value so the entering element can fade in.

Important Consideration

The two features solve different problems. transition-behavior permits discrete transitions, while @starting-style provides starting styles for entry transitions.

Using the transition Shorthand

The transition-behavior property is included in the transition shorthand.

Longhand Syntax

.example {
  transition-property: display;
  transition-duration: 0.3s;
  transition-timing-function: ease;
  transition-delay: 0s;
  transition-behavior: allow-discrete;
}

Equivalent Shorthand

.example {
  transition: display 0.3s ease 0s allow-discrete;
}

Multiple Properties

.example {
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}

Shorthand Reset Behavior

.example {
  transition-behavior: allow-discrete;
  transition: display 0.3s;
}

The second declaration resets transition-behavior to normal because the shorthand omits a behavior value.

Correct Declaration Order

.example {
  transition: display 0.3s;
  transition-behavior: allow-discrete;
}

Recommended Shorthand

.example {
  transition: display 0.3s allow-discrete;
}

Multiple Behavior Values

.example {
  transition-property: opacity, display;
  transition-duration: 0.3s, 0.3s;
  transition-behavior: normal, allow-discrete;
}

Each behavior value corresponds to a transition definition. When the number of values differs between transition longhand lists, CSS repeats or truncates values according to the transition list matching rules.

The transition-behavior property works with the other transition longhand properties.

transition

.example {
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}

Combines the transition components into a shorthand declaration.

transition-property

.example {
  transition-property: opacity, display;
}

Identifies which properties should transition.

transition-duration

.example {
  transition-duration: 0.3s;
}

Specifies the transition duration.

transition-timing-function

.example {
  transition-timing-function: ease;
}

Controls the rate of transition progress.

transition-delay

.example {
  transition-delay: 0.1s;
}

Specifies when the transition begins.

display

.example {
  display: none;
}

Controls an element's display type and whether it generates a box.

content-visibility

.example {
  content-visibility: hidden;
}

Controls whether an element's contents are rendered.

opacity

.example {
  opacity: 0;
}

Controls transparency and can interpolate continuously during a transition.

Complete Example

.panel {
  display: block;
  opacity: 1;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
  opacity: 0;
}
@starting-style {
  .panel:not(.is-hidden) {
    opacity: 0;
  }
}

Inheritance

The transition-behavior property is not inherited. Each element uses its own transition behavior unless inheritance is explicitly requested.

Parent Element

.parent {
  transition-behavior: allow-discrete;
}

Child Element

.child {
  transition-behavior: normal;
}

Explicit Inheritance

.child {
  transition-behavior: inherit;
}

Restore the Initial Value

.child {
  transition-behavior: initial;
}

This restores normal.

Using unset

.child {
  transition-behavior: unset;
}

Because the property is not inherited, unset restores the initial value.

Important Consideration

Applying allow-discrete to a parent does not automatically enable discrete transitions on its descendants.

Practical Examples

Fade-Out Panel

.panel {
  display: block;
  opacity: 1;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
  opacity: 0;
}

Fade-In and Fade-Out Panel

.panel {
  display: block;
  opacity: 1;
  transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
.panel.is-hidden {
  display: none;
  opacity: 0;
}
@starting-style {
  .panel:not(.is-hidden) {
    opacity: 0;
  }
}

Content Visibility Transition

.content-panel {
  content-visibility: visible;
  opacity: 1;
  transition: opacity 0.3s ease, content-visibility 0.3s allow-discrete;
}
.content-panel.is-hidden {
  content-visibility: hidden;
  opacity: 0;
}

Visibility Transition

.tooltip {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.2s ease, visibility 0.2s allow-discrete;
}
.tooltip.is-hidden {
  visibility: hidden;
  opacity: 0;
}

Transform and display

.menu {
  display: block;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease, display 0.3s allow-discrete;
}
.menu.is-hidden {
  display: none;
  opacity: 0;
  transform: translateY(-10px);
}
@starting-style {
  .menu:not(.is-hidden) {
    opacity: 0;
    transform: translateY(-10px);
  }
}

Reduced Motion Alternative

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
}

Removing transitions allows state changes to occur immediately while preserving the intended visible or hidden state.

transition-behavior Example

This interactive example uses a button to show and hide a panel. The panel combines an opacity transition with a discrete display transition. The @starting-style rule enables the entry fade.

HTML Example

<div class="discrete-demo">
  <button class="demo-toggle" type="button" aria-expanded="true" aria-controls="demo-panel">Hide Panel</button>
  <div class="demo-panel" id="demo-panel">
    <strong>Discrete Transition</strong>
    <p>This panel fades in and out while display changes between block and none.</p>
  </div>
</div>

CSS Example

.discrete-demo {
  padding: 15px;
}
.demo-toggle {
  padding: 10px 18px;
  border: 0;
  border-radius: 4px;
  background: #2563eb;
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.demo-toggle:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}
.demo-panel {
  display: block;
  opacity: 1;
  margin-top: 15px;
  padding: 20px;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  background: #eff6ff;
  transition: opacity 0.4s ease, display 0.4s allow-discrete;
}
.demo-panel p {
  margin-bottom: 0;
}
.demo-panel.is-hidden {
  display: none;
  opacity: 0;
}
@starting-style {
  .demo-panel:not(.is-hidden) {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .demo-panel {
    transition: none;
  }
}

JavaScript Example

const toggle = document.querySelector(".demo-toggle");
const panel = document.querySelector(".demo-panel");

toggle.addEventListener("click", () => {
  const hidden = panel.classList.toggle("is-hidden");
  toggle.setAttribute("aria-expanded", String(!hidden));
  toggle.textContent = hidden ? "Show Panel" : "Hide Panel";
});
Browser Result
Discrete Transition

This panel fades in and out while display changes between block and none.

Understanding the Results

Clicking the button changes the panel's display and opacity values.

Hiding the Panel

Opacity decreases from 1 to 0. The panel remains rendered until the transition completes, when display switches to none.

Showing the Panel

The panel switches to display: block at the beginning. The @starting-style rule supplies an initial opacity of zero so the panel can fade in.

Experiment With Duration

.demo-panel {
  transition: opacity 1s ease, display 1s allow-discrete;
}

Increasing both durations makes the entry and exit effects slower.

Experiment With Timing

.demo-panel {
  transition: opacity 0.4s linear, display 0.4s allow-discrete;
}

The opacity changes at a constant rate while the discrete display change follows its special switching rules.

Experiment Without allow-discrete

.demo-panel {
  transition: opacity 0.4s ease, display 0.4s;
}

Without allow-discrete, the display change is not transitioned. When hiding the panel, it disappears immediately rather than remaining visible for the opacity fade.

Accessibility Considerations

Discrete transitions can improve visual presentation, but hidden content and interactive controls must remain accessible and behave predictably.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
}

Maintain Keyboard Accessibility

Buttons that show and hide content should remain keyboard-operable and provide visible focus indicators.

Use Appropriate State Attributes

For disclosure controls, keep aria-expanded synchronized with the expanded or collapsed state.

Manage Focus When Hiding Content

If focus is inside a panel that is about to become hidden, move focus to an appropriate visible control when necessary.

Avoid Unexpected Delays

Long exit transitions can delay when hidden content is removed from the rendered page. Keep transitions short enough for responsive interaction.

Understand display: none

Content using display: none is normally removed from the accessibility tree and keyboard navigation when the hidden state takes effect.

Maintain Readable Content

Ensure that text and controls remain readable during opacity changes and do not become unexpectedly interactive while visually hidden.

Provide Functional Fallbacks

When discrete transition support is unavailable, the interface should still show and hide content correctly, even without animation.

Common Mistakes

Expecting Discrete Properties to Interpolate

The allow-discrete value permits discrete transitions but does not create intermediate values.

Omitting allow-discrete

.panel {
  transition: display 0.3s;
}

The default behavior does not enable the discrete display transition.

Forgetting @starting-style

Entry transitions from a non-rendered state may require @starting-style to establish starting values for interpolated properties.

Using an Invalid Value

.example {
  transition-behavior: discrete;
}

Use allow-discrete.

Forgetting Commas in Multiple Values

.example {
  transition-behavior: normal allow-discrete;
}

Separate multiple behavior values with commas.

Overwriting the Longhand With the Shorthand

.example {
  transition-behavior: allow-discrete;
  transition: display 0.3s;
}

The shorthand resets the behavior to normal.

Expecting a Transition Without a Duration

The transition-behavior property does not set a duration. A positive duration is generally needed for a visible transition.

Expecting Every Property to Transition

Not every CSS property supports transitions, even when allow-discrete is specified.

Confusing display and content-visibility

The properties have different effects on layout and rendering.

Ignoring Browser Support

Discrete transitions and @starting-style are newer CSS features and should be tested in supported browsers.

Ignoring Hidden Interactive Content

Ensure that controls do not remain unexpectedly focusable or usable while a panel is visually hidden.

Ignoring Reduced Motion Preferences

Provide an immediate state-change alternative when users request reduced motion.

Important Considerations

Keep the following points in mind when using transition-behavior:

  • The property controls whether discrete animation behavior is permitted in CSS transitions.
  • The initial value is normal.
  • The property is not inherited.
  • The property accepts normal and allow-discrete.
  • Multiple behavior values can be separated by commas.
  • The normal value does not permit transitions for properties with discrete animation behavior.
  • The allow-discrete value permits eligible discrete transitions.
  • Discrete transitions do not interpolate continuously between values.
  • Most discrete transitions switch values at the midpoint.
  • The display property has special switching behavior when entering or leaving a rendered state.
  • The content-visibility property also has special visible-state switching behavior.
  • Entry transitions from non-rendered states may require @starting-style.
  • The property is a longhand component of the transition shorthand.
  • The shorthand can include the allow-discrete keyword.
  • Declaring the shorthand resets omitted transition components.
  • The property does not specify transition duration, delay, or timing function.
  • It does not guarantee that every CSS property can transition.
  • Opacity and transforms can be combined with discrete property transitions.
  • Transitions should not interfere with keyboard interaction.
  • Hidden content should have appropriate focus and accessibility behavior.
  • Respect reduced motion preferences.
  • Provide functional fallbacks when discrete transitions are unsupported.
  • Test newer transition features across supported browsers.

Browser Support

The CSS transition-behavior property is a newer CSS feature and has more limited historical browser support than traditional CSS transitions. Modern browsers increasingly support allow-discrete, but compatibility should be checked when using discrete transitions involving display or content-visibility.

For current compatibility information, visit Can I Use? and search for transition-behavior.

Basic Declaration

.example {
  transition-behavior: allow-discrete;
}

Shorthand Declaration

.example {
  transition: display 0.3s allow-discrete;
}

Feature Detection

@supports (transition-behavior: allow-discrete) {
  .panel {
    transition: opacity 0.3s ease, display 0.3s allow-discrete;
  }
}

Fallback Example

.panel {
  transition: opacity 0.3s ease;
}
@supports (transition-behavior: allow-discrete) {
  .panel {
    transition: opacity 0.3s ease, display 0.3s allow-discrete;
  }
}

Testing Recommendations

Test entry and exit transitions, @starting-style, discrete switching behavior, and keyboard interaction in the browsers your website supports. Feature detection confirms syntax recognition but does not guarantee identical behavior for every property.

Specifications

The transition-behavior property is defined in the CSS Transitions Level 2 specification.

CSS Transitions Level 2 - The transition-behavior Property

The specification defines the normal and allow-discrete values and their role in determining which property changes can start transitions.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: transition-behavior