The CSS Working Group has approved a proposal that would let developers animate and transition to and from display: none. The conceptual hurdle is built into the property itself: setting display to none terminates any running animation on the element and its descendants, and changing display away from none restarts every animation applied via animation-name, including those on displayed descendants.

Setting the display property to none will terminate any running animation applied to the element and its descendants. If an element has a display of none, updating display to a value other than none will start all animations applied to the element by the animation-name property, as well as all animations applied to descendants with display other than none.

Giving non-none values priority

That circularity makes the idea look dead on arrival, but the spec text suggests a way around it: if @keyframes allowed any display value other than none, then none could no longer cancel or restart the animation, giving non-none values priority so none is only applied once the animation or transition has finished.

This is not interpolation between keywords like block and none; there are no intermediate values between them. The animation remains discrete, and the value switches once it completes. As Miriam Suzanne described in a Mastodon post, block stays intact until things stop moving, at which point none can be safely applied.

Animation example

Robert Flack's example from the discussion shows the first frame setting the element to display: block, which takes priority over the underlying display: none because it is a non-none value. The animation runs to completion without being cancelled, since none resolves only afterward.

@keyframes slideaway {
  from { display: block; }
  to { transform: translateY(40px); opacity: 0;}
}

.hide {
  animation: slideaway 200ms;
  display: none;
}

Transition example

Suzanne's example, which she referenced on Mastodon, uses a transition instead. The underlying display starts at none, so the element is out of the document flow entirely:

.hide {
  transition: opacity 200ms, display 200ms;
  display: none;
  opacity: 0;
}

Triggering the transition on hover should make the element fade in at 200ms. As with the animation case, the display values toggle, but block takes priority so the transition is not cancelled up front and is applied after opacity finishes.

.hide:hover {
  display: block;
  opacity: 1;
}

Questions still open

Plenty remains to be resolved. For example, if an element has multiple animations assigned, it is unclear whether none would reset or cancel them. Infinite animations and reversed directions are among the other scenarios still to be worked through.