Why CSS display Cannot Be Animated Directly
The CSS display property cannot be animated using transitions or keyframe animations. This is because display determines the fundamental box type and layout participation of an element, and browsers cannot interpolate between two display states.
display: none → display: block or any other value changes the element instantly; no smooth transition occurs.
CSS transitions only work on properties that can be interpolated numerically or smoothly over time, such as opacity, width, height, transform, etc.
To create a visual hide/show effect, use opacity or visibility along with height or max-height to animate elements smoothly.
After a transition completes, you can then toggle display via JavaScript to remove the element from layout if needed.
In this example, the element fades in and out smoothly using opacity. If display were toggled directly, the element would appear or disappear instantly without any transition.
Use opacity or visibility for smooth show/hide animations.
Combine max-height or transform for more complex expanding/collapsing effects.
Use display in JavaScript only after a transition ends to remove the element from the layout completely.
Test accessibility when hiding elements; use visually hidden techniques instead of display: none when content must remain available to screen readers.