Command Palette

Search for a command to run...

CSS Animation vs Transition: Keyframes Explained

CSS Animation vs Transition: Keyframes Explained

T
Toolz Team
|Sep 13, 2026|18 دقيقة قراءة

جزء من مجموعة CSS والتصميم

مولد الرسوم المتحركة CSS

قم بإنشاء رسوم متحركة للإطار الرئيسي لـ CSS من الإعدادات المسبقة مثل التلاشي والانزلاق والارتداد والدوران. اضبط المدة والتيسير والتأخير والتكرار والاتجاه، وقم بالمعاينة المباشرة، ثم انسخ الإطارات الرئيسية واختصار الرسوم المتحركة.

استخدم مولد الرسوم المتحركة CSS

Every developer has copied a block of @keyframes from a Stack Overflow answer, pasted it in, refreshed, and found the element sitting perfectly still. Nine times out of ten the reason is boring: the animation name in the @keyframes rule did not match the name in the animation shorthand, or the duration was left at zero, or the class never landed on the element. The other reason is that keyframe animation is one of those corners of CSS where you cannot judge the result by reading the code. A sequence of percentages and transforms tells you nothing about whether the motion feels smooth, snappy or seasick until you watch it run.

A CSS animation is the browser's mechanism for moving an element through a named sequence of styles over time. Unlike a transition, which animates a single change and waits for a trigger, an animation follows a @keyframes script with as many steps as you like, can loop forever, and starts on its own the moment it is applied. It is what powers loading spinners, attention pulses, entrance effects, and every bit of ambient motion that makes an interface feel alive. But the two halves, the keyframes and the shorthand, have to agree exactly, and the shorthand packs seven or eight values into one line in an order most people never memorize.

The CSS Animation Generator removes the guesswork. You pick a motion from a library of presets, adjust the duration, easing, delay, iteration count and direction, and watch it play on a live preview element. The tool writes both the @keyframes rule and the matching animation shorthand into a copy-ready box, with the names already in sync, so the block you paste works the first time.

TL;DR: A CSS animation moves an element through a @keyframes sequence over time, and unlike a transition it needs no trigger and can loop. The @keyframes name and the animation-name must match exactly, which is the single most common reason an animation does nothing. The shorthand carries name, duration, timing-function, delay, iteration-count, direction and fill-mode. Prefer animating transform and opacity for smooth, composited motion. This generator gives you fourteen presets, full playback control and a live preview, and emits both the keyframes and the shorthand together. It runs entirely in your browser with no signup.

What problem does a CSS animation generator solve?

The awkward thing about keyframe animation is the round trip. To tune a bounce by hand you write the @keyframes rule, write the animation line, save the file, switch to the browser, wait for the reload, and watch. If the bounce is too aggressive you change one translateY value and do the whole loop again. Because that cycle is slow, most people accept the first version that does not look broken rather than the version that feels right, and the difference between those two is exactly the polish that separates a considered interface from a template.

A generator collapses that loop into a single click. You choose a preset, drag the duration slider, and the preview element plays the motion in front of you immediately. Switch the timing function from ease to a bezier curve and the change in feel is instant. Set the iteration count to infinite and the animation loops so you can study it. After a few minutes of this you build an intuition for what six hundred milliseconds looks like against twelve hundred, which is the sense you need to make good motion decisions everywhere else.

There is a correctness argument too. You cannot produce a malformed animation value by choosing from menus and dragging sliders, and you cannot mistype the keyframe name, because the tool binds the shorthand to the keyframes it generated. The output is always safe to paste. That reliability is the same reason I keep visual CSS builders close for other properties, the same instinct behind reaching for the gradient generator instead of counting colour stops in my head, or the box-shadow generator instead of guessing at blur radii.

How is a CSS animation different from a CSS transition?

This trips people up constantly, so it is worth being precise. A transition animates a single property between two states and requires something to change, a hover, a focus, a toggled class, before it runs. It has a start value and an end value and nothing in between. An animation, by contrast, follows a @keyframes rule that can define any number of intermediate steps, so the element can move through a whole choreography rather than a straight line from A to B. It also does not wait for anything: apply it and it plays.

The practical consequence is that you reach for a transition when you want to smooth a state change, and for an animation when you want motion that is intrinsic to the element. A button that darkens on hover is a transition. A spinner that rotates forever, a badge that pulses to draw the eye, or a card that slides up as the page loads are all animations, because the motion happens on its own and often repeats. If you are still deciding which one a given effect needs, the rule of thumb is simple: if a user action starts it and it goes one way, use a transition; if it plays by itself, loops, or has more than two steps, use an animation. The CSS transition generator is the companion tool for the first case, and the two cover most of the motion you will ever write.

Aspect Transition Animation
Trigger Needs a state change (hover, focus, class) Starts on its own when applied
Steps Two, a start and an end Any number, via @keyframes
Looping No, runs once per change Yes, with iteration-count
Typical use Hover and focus effects Spinners, pulses, entrances

What is the correct order of the animation shorthand?

The animation shorthand is dense. It can carry the keyframe name, duration, timing-function, delay, iteration-count, direction, fill-mode and play-state, all on one line, and the order matters for the two time values in exactly the way it does for transitions. This generator writes the name first, then duration and timing-function, then the optional delay, then iteration-count, direction and fill-mode, for example animation: fadeIn 0.6s ease 1 both. Writing the name first is legal because keyframe names are not CSS keywords, and it reads more clearly than burying the name at the end.

The one rule that catches everyone is the two time values. The duration and the delay are both times, and CSS tells them apart only by position: the first time value is the duration and the second is the delay. Everything else in the shorthand is a keyword or a unitless number, so it cannot be confused with a time. That is why the tool can safely drop the delay when it is zero, because a unitless 1 or the word infinite that follows is unmistakably the iteration count, not a second time. The generator also omits any value that equals its CSS default, so a normal direction or a none fill-mode never clutters the output. The result is a shorthand that reads the way you would write it by hand once you knew the rules.

Why is my CSS animation not playing?

This is the cliff, and almost everyone walks off it at least once. The single most common cause is a mismatch between the animation-name and the name in the @keyframes rule. A typo, a capitalization difference, or a name that was renamed in one place and not the other leaves the browser with no keyframe rule to bind to, so it silently does nothing. There is no error and no warning; the element simply sits there. Because this generator writes both halves together from the same name, that entire class of bug disappears, which is a large part of the point.

The other causes are worth knowing because they show up when you hand-write animations. A duration of zero means the animation completes instantly and you never see it. An element that is display: none does not run its animations at all, so a fade-in that depends on the element being rendered will not fire. A missing or misspelled property inside a keyframe is quietly ignored rather than flagged. And an animation with animation-fill-mode: none, the default, snaps the element back to its unanimated styles the instant it finishes, which can look like it never ran if the motion was subtle. Watching the animation in a live preview surfaces most of these in seconds, which is the case for building motion where you can see it rather than in a file you keep reloading.

What does animation-fill-mode do?

Fill mode is the setting people understand last and need most. It decides what styles the element shows outside the animation's active window, both before it starts during any delay and after it finishes. The default, none, means the element ignores the first and last keyframes when the animation is not running, so it sits in its normal styles before the animation and snaps back to them after. That snap-back is the source of a very common frustration: you animate an element to fade in, it fades in beautifully, and then it vanishes again the moment the animation ends, because with none the final opacity: 1 keyframe is discarded once the animation is over.

The fix is animation-fill-mode: forwards, which keeps the last keyframe applied after the animation finishes, so the faded-in element stays visible. backwards applies the first keyframe during any delay before the animation starts, which is useful when you have a delay and do not want the element to flash in its default state first. both does both at once and is the safest general choice for entrance animations, which is why this generator defaults new animations to both. Understanding fill mode is the difference between an entrance that lands and one that undoes itself, and it is far easier to grasp by toggling it in a preview and watching the ending change than by reading the specification cold.

When should an animation loop, and how do I control it?

Iteration count decides how many times the animation runs. Set it to a positive whole number and the animation repeats that many times and then stops; set it to infinite and it loops forever. Looping animations are the right choice for ambient, ongoing motion, a spinner that shows work is happening, a pulse that keeps a call-to-action alive, a subtle float that gives a hero image some life. One-shot animations, run once, are for entrances and exits, where the motion has a clear beginning and end and repeating it would be distracting.

Direction pairs with iteration count to shape how each pass runs. The default normal plays every iteration from the first keyframe to the last. reverse plays each one backward. alternate runs the first pass forward and the next backward, ping-ponging between the endpoints, which is how you build a smooth back-and-forth pulse without defining a return trip in the keyframes. alternate-reverse starts backward and alternates from there. The generator exposes all four so you can feel the difference: a pulse with alternate breathes in and out naturally, while the same keyframes with normal and an even number of steps have to encode the return themselves. For looping motion, alternate almost always produces the more organic result with less keyframe work.

Which properties should I animate for smooth performance?

The properties you animate decide whether the motion runs at a smooth sixty frames a second or stutters, and the choice is the same as for transitions. Prefer transform and opacity. Both can be handed to the compositor and animated without the browser recalculating the page layout, so they stay smooth even on modest hardware and under load. This is why a card that slides up with transform: translateY feels effortless while the same card animated with top or margin-top feels rough. Every entrance preset in this generator is built on transform and opacity for exactly this reason.

The properties to avoid animating in a keyframe sequence are the ones that trigger layout: width, height, top, left, margin and padding. Changing any of these forces the browser to recompute the geometry of the element and everything around it on every frame, which is expensive and is the most common cause of janky animation, made worse when the animation loops and pays that cost continuously. If you want an element to grow, a transform: scale is almost always cheaper than animating width and height, and it looks nearly identical. The broader argument for assembling a set of tools that steer you toward the cheap path is in the web developer toolkit piece, and the workflow habits that make motion a quick decision rather than a slow one are in the developer productivity tools guide.

How does the generator keep the preview honest?

Every visual builder risks the preview and the exported code drifting apart until the tool teaches you a value that will not reproduce. This generator injects the exact @keyframes rule it outputs into the page and applies the exact animation shorthand it shows you to the preview element, so the motion you watch is the motion your copied CSS will produce. There is no separate animation path that could disagree, and the keyframe name in the preview is the name in the output.

Because an animation runs on mount and then finishes, the preview needs a way to replay it, which the tool handles by remounting the preview element when you press replay. That mirrors how a one-shot animation behaves in production, where it plays when the element appears and then holds its final state according to the fill mode. The output stays minimal too, dropping the zero delay and any default value so you copy only meaningful declarations, the same discipline of emitting nothing redundant that runs through the CSS filter generator and the other visual builders. When you pair a keyframe animation with a layout that positions the element, the flexbox generator is a natural companion for building the surrounding structure.

What browsers support CSS animations?

CSS animations are supported in every current browser and have been for well over a decade. The @keyframes rule, the animation shorthand and all of its longhands are universal and unprefixed, so the output of this generator works in Chrome, Firefox, Safari and Edge with no vendor prefixes or fallbacks. The definitive reference is the CSS Animations Level 1 specification from the W3C, which is the primary source for how each part of the shorthand behaves, and it is worth reading once the generator has given you a physical feel for what the pieces do. For accessibility, remember that some users set a prefers-reduced-motion preference, and it is good practice to wrap non-essential looping animation in a media query that respects it, so ambient motion can be turned off for people who find it uncomfortable.

If you are assembling a wider set of visual CSS tools, the transition generator and the CSS transform generator sit naturally alongside this one, since transforms are the raw material most of these animations move and transitions handle the state changes animations do not. Everything here runs client-side, and the CSS you copy is yours to use with no runtime, no build step and no dependency.

Frequently asked questions

What is a CSS animation generator?

A CSS animation generator is a visual tool that builds a keyframe animation from settings you choose. You pick a preset, set the duration, easing, delay, iteration count and direction, and it outputs the @keyframes rule and the animation shorthand together with a live preview you can replay.

What is the difference between a CSS animation and a CSS transition?

A transition animates a single change between two states and needs a trigger such as hover to run. An animation follows a @keyframes sequence with any number of steps, can loop, and starts on its own as soon as it is applied, without waiting for a state change.

What order does the animation shorthand use?

This tool writes the keyframe name first, then duration, timing-function, delay, iteration-count, direction and fill-mode, for example animation: fadeIn 0.6s ease 1 both. The first time value is always the duration and the second is the delay, so a single time value is read as the duration.

How do I make a CSS animation loop forever?

Set the iteration count to infinite. In the shorthand that is the word infinite, as in animation: spin 1s linear infinite. Any positive whole number instead repeats the animation that many times and then stops according to the fill mode and direction.

Why is my CSS animation not playing?

The most common cause is a mismatch between the animation-name and the @keyframes name, including a typo or a case difference, which leaves the browser with no rule to bind to. Also check that the duration is above zero and that the element is rendered, since an animation on a display: none element does not run.

What does the animation-fill-mode property do?

Fill mode decides what styles the element shows before the animation starts and after it ends. The default none snaps the element back to its normal styles when the animation finishes. Setting forwards keeps the final keyframe, backwards applies the first keyframe during a delay, and both does both.

Which properties should I animate for smooth performance?

Prefer transform and opacity. The browser can animate them on the compositor without recalculating layout, so they stay smooth at 60fps. Animating width, height, top, left or margin forces a layout recalculation on every frame, which is the usual reason an animation stutters.

Is the generated animation CSS free and safe to use?

Yes. The tool is completely free with no signup or usage limits, and it emits standard, unprefixed CSS supported in every modern browser. All processing happens in your browser, so nothing is uploaded and the tool works offline once loaded.

Comments

0 comments

0/2000 characters

No comments yet. Be the first to share your thoughts!