CSS animation property

CSS animation property

CSS animation Property

The animation property is a shorthand that combines multiple animation-related properties into a single declaration. It allows you to create smooth and dynamic animations in CSS.

1. Syntax

selector { animation: name duration timing-function delay iteration-count direction fill-mode play-state; }

2. Accepted Values

PropertyDescriptionExample
nameName of the @keyframes animationslide
durationHow long the animation runs2s, 500ms
timing-functionControls the speed curveease, linear, ease-in-out
delayTime before animation starts0s, 1s, -2s
iteration-countNumber of times animation runs1, infinite, 3
directionDirection of animation playbacknormal, reverse, alternate
fill-modeDefines styles before/after animationnone, forwards, backwards
play-stateControls animation staterunning, paused

3. Example – Simple Animation

.box { width: 100px; height: 100px; background: red; animation: move 3s ease-in-out infinite; } @keyframes move { from { transform: translateX(0); } to { transform: translateX(300px); } }

✅ The box moves right and resets continuously.

4. Example – Full Animation Shorthand

.box { animation: bounce 2s ease-in 1s infinite alternate forwards running; } @keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-50px); } }

✅ The box bounces up and down with a 1s delay.

5. Best Practices

Use shorthand for cleaner code.
Set forwards fill-mode to maintain the final state.
Use infinite iteration for continuous animations.

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close