APlays Only Once Similarly a CSS animation will only cycle one time unless you specify a number of iterations with the animationiterationcount parameter. This value can beor infinite if you want the animation to loop forever. Try uncommenting the animationiterationcount rule below. Animated Element Resets at the End Say you have an animation that starts in one state like black text and ends in another state like purplecolored text. If this animation only plays once youd probably want the color to stay purple after the animation completes. However by default CSS animations will change back to the elements preanimated state after an animation finishes.
Make the animation look broken. The good news is that CSS animations have a solution the animationfillmode property. This property instructs the animated element to retain the styles from the first andor last keyframe of the animation. Watch the example below. After the text color changes to purple youll see it flip back to black. But if we Digital Marketing Service uncomment the rule animationfillmode forwards we see the text remain purple. This is because animationfillmode forwards takes the last keyframe style purple text and applies it to the element after the animation cycle. Animation Starts Too Soon Sometimes you may want to add a short delay before the start of an animation for a better user experience.
Accomplish this with the animationdelay property. Below the animation has a delay of 4s four seconds. NonAnimatable CSS Properties Another reason why your animation isnt working might be that youre attempting to animate a CSS property that isnt animatable. Check our list of animatable CSS properties for the property youre trying to animate and make sure its there. Otherwise youll need to find another way to achieve a similar effect. Alternatively you can look up the property in Mozillas CSS properties reference then look for an Animation type under Formal definition. This documentation will show you the different ways.