Free tool · Developer tools
CSS animation generator
The default is a slide up of 24px over 0.6s that runs once and ends visible. It gives a 10-line @keyframes block and the shorthand slide-up 0.6s ease 0s 1 normal both.
- Free
- No sign-up
- Runs in your browser
- Total time 0.6s
- Animates opacity, transform
@keyframes slide-up {
from {
opacity: 0;
transform: translateY(24px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animated {
animation: slide-up 0.6s ease 0s 1 normal both;
}
@media (prefers-reduced-motion: reduce) {
.animated {
animation: none;
}
}How to use the CSS Animation Generator
- Choose an Animation. The preview box plays it at once.
- Set the Duration, Delay, Repeats, Timing function, Direction and Fill mode.
- Change Distance or Scale to make the movement larger or smaller, and press Replay to watch it again.
- Press Copy the CSS and put it in your stylesheet, then add the class
animatedto the element.
How do you create a CSS animation?
A CSS animation has two parts. The @keyframes block names the steps, and the animation property on an element plays them. The default builds a block called slide-up with a from step at opacity 0, shifted 24px down, and a to step at opacity 1 in its place. The element then reads slide-up 0.6s ease 0s 1 normal both and moves into view in 0.6 seconds.
The generator has seven animations, listed in the table with the properties each one changes. Animating opacity and transform only is a good habit, because browsers can draw those changes without recalculating the layout of the page.
| Animation | Changes | Keyframe steps |
|---|---|---|
| Fade in | opacity | from, to |
| Slide up | opacity, transform | from, to |
| Zoom in | opacity, transform | from, to |
| Bounce | transform | 0% and 100%, 50% |
| Pulse | transform | 0% and 100%, 50% |
| Spin | transform | from, to |
| Shake | transform | 0% and 100%, 20% and 60%, 40% and 80% |
What does each part of the animation shorthand mean?
The shorthand is written in a fixed order in the copied CSS: name, duration, timing function, delay, repeats, direction and fill mode. For the default that reads slide-up 0.6s ease 0s 1 normal both. Two time values appear, and the first is always the duration while the second is the delay, which is why the generator always writes both.
Fill mode matters more than it looks. With none an element snaps back to its normal style when the animation ends, and during a delay a fade in shows the element fully before it jumps to opacity 0 and starts. forwards keeps the last step, both also applies the first step during the delay, and both is the right choice for entrance animations with a delay.
| Part | Value | What it sets |
|---|---|---|
| Name | slide-up | Links the rule to the @keyframes block |
| Duration | 0.6s | Time for one run |
| Timing function | ease | Speed curve inside a run |
| Delay | 0s | Wait before the first run |
| Repeats | 1 | How many runs |
| Direction | normal | Which way each run plays |
| Fill mode | both | Styles kept before and after |
How long does a CSS animation run in total?
The total time is the delay plus the duration times the number of repeats. The default is 0.6s: no delay, 0.6 seconds, one run. A shake of 0.3 seconds repeated three times after a 0.5 second delay takes 1.4s. An infinite animation never ends, so the chip says it runs until stopped.
The direction does not change the total. An alternate animation still counts each pass as one repeat, so a bounce of 0.4 seconds with 5 repeats takes 2 seconds whether it is set to normal or alternate.
| Duration | Repeats | Delay | Total time |
|---|---|---|---|
| 0.6s | 1 | 0s | 0.6s |
| 0.3s | 3 | 0.5s | 1.4s |
| 1s | 2 | 0.2s | 2.2s |
| 2s | 5 | 0s | 10s |
| 0.4s | infinite | 0s | Runs until stopped |
How do you stagger the animation across a list?
Give each item the same animation with a different delay. For five list items with a step of 0.1 seconds, the delays run 0s, 0.1s, 0.2s, 0.3s, 0.4s. Set the delay of each item inline or with a custom property, and keep the fill mode on both so items wait in their first step instead of showing early.
Starting the first item at 0.3 seconds with a step of 0.15 gives 0.3s, 0.45s, 0.6s, 0.75s for four items. Keep the whole sequence short, because the last item should appear before a visitor has finished reading the first. The copied CSS ends with a prefers-reduced-motion rule that turns the animation off for people who have asked their device for less motion.
Use it with
- Box Shadow Generator: visual CSS box-shadow builder.
- CSS Grid Generator: build a CSS grid layout and copy the code.
- CSS Cubic Bezier Generator: CSS cubic bezier generator: set four numbers or pick a curve, see the graph, test it on a moving dot and copy the cubic-bezier() CSS.
Questions
How do I make a CSS animation?
Write a @keyframes block with a name and steps, then set the animation property on an element with that name and a duration. The default is slide-up 0.6s ease 0s 1 normal both.
What is the order of the animation shorthand?
Name, duration, timing function, delay, iteration count, direction, fill mode. The first time value is the duration and the second is the delay.
How do I make an animation run forever?
Set the repeat count to infinite. The generator has an Infinite choice under Repeats and writes the word infinite in the shorthand.
Why does my element jump back after the animation?
The fill mode is none, so the element returns to its normal style. Set it to forwards or both to keep the final step.
How long will my animation take?
Delay plus duration times repeats. The default takes 0.6s, and 0.3 seconds repeated 3 times after a 0.5 second delay takes 1.4s.
Does the page keep my settings?
No. The settings are used for the preview and the CSS on your screen and go no further.
The tool's results are computed in your browser by the code on this page; the explanations are checked against the tool's own output.