# CSS Animations with only one keyframe

DevFeed: [CSS Animations with only one keyframe](<https://devfeed.tech/articles/css-animations-with-only-one-keyframe-52060.md>)

Original publisher: [Read original article](<https://lea.verou.me/2012/12/animations-with-one-keyframe/>)

Author: Lea Verou

Published: 2012-12-12T00:00:00Z

Content type: article

Language: en

Sources: [Lea Verou's blog](<https://devfeed.tech/sources/lea-verou-s-blog.md>)

Topics: [CSS](<https://devfeed.tech/topics/css.md>), [web animation](<https://devfeed.tech/topics/web-animation.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [animation](<https://devfeed.tech/tags/animation.md>), [animations](<https://devfeed.tech/tags/animations.md>), [blog](<https://devfeed.tech/tags/blog.md>), [css](<https://devfeed.tech/tags/css.md>), [css-animation](<https://devfeed.tech/tags/css-animation.md>), [css-animations](<https://devfeed.tech/tags/css-animations.md>), [easing](<https://devfeed.tech/tags/easing.md>), [tips](<https://devfeed.tech/tags/tips.md>)

## AI overview

CSS animations can omit `from` and `to` keyframes when their intended values match the element's computed styles: the browser constructs missing 0% and 100% keyframes from those values. In the heart example, this reduces the animation to a single `50%` keyframe that scales the heart. For a more natural pulse, the excerpt instead sets only `to { transform: scale(1.4); }` and uses `alternate`, which reverses each even iteration and also reverses the timing (easing) function on reversed iterations.

## Source excerpt

This is a very quick tip, about a pet peeve of mine in almost every CSS animation I see. As you may know, I'm a sucker for reducing the amount of code (as long as it remains human readable of course). I demonstrated a very similar example in my "CSS in the 4th dimension" talk, but I recently realized I never blogged about it (or seen anyone else do so). Lets assume you have a simple animation of a pounding heart, like so: @keyframes pound { from { transform: none; } 50% { transform: scale(1.4); } to { transform: none; } } .heart { /* ... */ animation: pound .5s infinite; } You can see the problem already: the shrunk heart state is repeated twice in the keyframes (from and to). You probably know you can combine them into one rule, like so: @keyframes pound { from, to { transform: none; } 50% { transform: scale(1.4); } } What many don't know, is that you don't need these two keyframes at all, since they basically replicate the same state as the one in the .heart rule. To quote the CSS Animations spec: If a 0% or "from" keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or "to" keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated. Therefore, the code could actually be as simple as: @keyframes pound { 50% { transform: scale(1.4); } } This trick is very useful for providing fallbacks that are the same as the first or last keyframe, without having to repeat them in the @keyframes rule. Of course it doesn't only apply to animations where you only have one keyframe beyond from and/or to. You can omit the from and to keyframes in every animation, when you want them to be the same as the styles that are applied to the element anyway. Of course, to make this particular animation appear more natural, it would be much more wise to do something like this, still with only one keyframe (the from state is dynamical