Animating display none and height auto
New properties and functions will enable you to animate properties that, until now, were not animatable. We'll look at the following properties: * `transition-behavior` * `calc-size()` * `@starting-style` used to: * Change the height of an element from 0 to auto * Change the value of display from none to block ## The code These are the properties we'll use for these examples. ### `transition-behavior` The `transition-behavior` property specifies whether transitions will be started for properties whose animation behavior is [discrete](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior#examples). !!! note **Discrete definition** Discrete properties' values are not additive, and interpolation swaps from the start value to the end value at 50%. Specifically, denoting p as the progress value: * If p < 0.5, then V_result = V_start * If p ≥ 0.5, then V_result = V_end !!! ### `calc-size()` The `calc-size()` function allows math to be performed on intrinsic sizes, just like you can use `calc()` to perform math on extrinsic sizes. ### `@starting-style` The `@starting-style` at-rule is used to define starting values for properties set on an element that you want to transition from when an element is first displayed on a previously loaded page. The `@starting-style` at-rule can be used in two ways: 1. As a standalone block that contains one or more rulesets defining starting style declarations and selecting the elements they apply to 2. Nested within an existing ruleset, that contains one or more declarations defining starting property values for the elements already selected by that ruleset ## How it works The HTML we'll work with is simple. * A button element with the class `toggle` * A div element with the class `container` ```html
Some Title
Some content
Supported | 127
Supported | 17.6 - TP
Supported | 129 - 131
Partial support
Doesn't animate from `display: none` | The mobile support is a little more spotty. Unknown support for Opera Mini and UC browsers likely means it's not supported. As for other browsers, Firefox doesn't provide support in its Android version, I wonder if it's because a different team develops the Android version | Chrome for Android | Safari on iOS* | Samsung Internet | Opera Mini* | Opera Mobile* | UC Browser for Android | Android Browser* | Firefox for Android | | --- | --- | --- | --- | --- | --- | --- | --- | | 127
Supported | 17.5
Supported | 25
Supported | Unknown support | 80
Supported | 15.5
Unknown support | 127
Supported | 127
Not supported | With this data in mind, we should look at these transitions as progressive enhancements at least until Firefox adds the feature in Android and finishes the feature for desktop. ## Further work We've covered animating from `display: none` and to `height: auto`. A future step is to research what other discrete properties can we transition as described in [Not Fully Animatable CSS properties](https://vallek.github.io/animatable-css/#not-full-anim). There are other properties similar to `calc-size` that would work with different types of discrete properties. These are: * [color-mix()](https://drafts.csswg.org/css-values-5/#color-mix) for color interpolation * [cross-fade()](https://drafts.csswg.org/css-values-5/#cross-fade) for image interpolation * [transform-mix()](https://drafts.csswg.org/css-values-5/#transform-mix) for interpolated transform values * [mix()](https://drafts.csswg.org/css-values-5/#mix) for general-purpose interpolated value It'll be interesting to see how these properties work once they are implemented. ## Video Tutorials