CSS Keyframe Animation Generator

How to use 4 steps
  1. Pick an Animation.
  2. Set the Duration, Delay, Timing function, Direction and Fill mode.
  3. Set a Repeat count or tick Repeat forever.
  4. Press Copy Animation CSS and paste it into your stylesheet.
Animated
Generated CSS Code

How this tool works

An animation is two things: a set of keyframes describing what changes, and a shorthand saying how it runs. The keyframes here are ready-made, and every part of the shorthand is yours — duration, delay, timing function, direction, fill mode and how many times it repeats. Those settings change the character of the movement far more than the choice of keyframes does.

Animating transform and opacity is what keeps movement smooth: both can be handled without the browser recalculating layout, where animating width, height, top or left forces it to redo that work on every frame. All six keyframe sets here stay on transform and opacity for that reason. A reduced-motion block is generated alongside, because a reader who has asked their system for less movement has asked for a reason.

Settings that decide how it feels

  • Fill mode decides what happens at the ends: by default an element snaps back to its unanimated state when the animation finishes. forwards holds the final keyframe, which is what a one-shot entrance animation almost always wants.
  • Direction is how you avoid a jump: a looping animation that ends somewhere other than where it started will snap back each time. alternate runs it forwards then backwards instead, so the loop is seamless.
  • Infinite movement is tiring in an interface: a permanently pulsing element competes with everything else on the page for attention. Reserve it for genuine loading states.
  • The reduced-motion block is not optional courtesy: vestibular disorders make large or repeated motion genuinely unpleasant. Honouring the system setting costs three lines.

Keyframes and the shorthand are separate things

An animation is two pieces. The @keyframes block describes what changes. The animation shorthand on the element says how it runs — duration, timing function, delay, iteration count, direction, fill mode.

The shorthand is where most of the character comes from. The same keyframes at 200ms with an ease-out read as responsive; at 2s with a linear timing they read as decorative. The [msm_tool slug="css-animation"] gives you every part of it rather than only a duration.

Animate transform and opacity

This is the performance rule that actually matters, and it is short.

Changing transform or opacity can be handled by the compositor without recalculating layout or repainting. Changing width, height, top, left, margin or padding forces the browser to redo layout on every frame, for every element affected.

The practical translation:

  • Move things with transform: translate(), not top and left.
  • Resize with transform: scale(), not width and height.
  • Fade with opacity, not by changing a colour's alpha.
  • Rotate with transform: rotate(), which has no layout equivalent anyway.

An animation that stutters is almost always animating a layout property. Switching it to a transform usually fixes it outright.

Fill mode decides what happens at the end

By default an element snaps back to its unanimated state the moment the animation finishes. For a looping animation that is invisible. For a one-shot entrance it is the bug people report as "my animation runs and then everything jumps".

forwards holds the final keyframe, which is what an entrance almost always wants. backwards applies the first keyframe during any delay, which stops an element flashing at its natural position before the animation starts. both does each.

If you set a delay and see a flash before the movement begins, backwards is the fix.

Direction, and avoiding the jump

A looping animation whose last keyframe differs from its first will snap back each time round. alternate runs it forwards then backwards instead, so the loop is seamless without writing a return journey into the keyframes.

That halves the keyframe work for anything that pulses, breathes or sways, and it is why those effects usually need only two keyframes rather than three.

The easing applies between each pair of keyframes

Not across the whole sequence. This one catches people out.

Adding ease-in-out to a four-keyframe animation eases four separate times, producing a visible stutter at each keyframe rather than one smooth arc. If you want a single curve across the whole thing, use two keyframes and let the timing function do the shaping. If you genuinely need intermediate positions, consider linear between them so the steps do not fight each other.

Infinite motion is tiring

A permanently animating element competes with everything else on the page for attention, and it does not stop competing. Reserve infinite loops for genuine loading states, where the movement is telling the user something is happening.

A pulsing call-to-action button is the classic misuse. It draws the eye once and irritates thereafter, and on a page someone uses daily it becomes a reason to leave.

Reduced motion is not optional courtesy

Vestibular disorders make large or repeated motion genuinely unpleasant — nausea and dizziness rather than mild annoyance. Operating systems expose a setting for it, browsers pass it through, and honouring it costs three lines:

@media (prefers-reduced-motion: reduce) { .animated { animation: none; } }

The generated CSS includes that block. A more considered approach is to reduce rather than remove — keep a fade, drop the movement — since an interface with no transitions at all can be harder to follow. Either is better than ignoring the request.

Animation or transition

A transition runs between two states when something changes: a hover, a class being added, a value updating. It needs a trigger and it goes one way and back.

An animation runs on its own through keyframes, can loop, and can have as many intermediate steps as you like. If the movement has a start and an end tied to an interaction, it is a transition. If it runs by itself or needs more than two points, it is an animation.

Frequently Asked Questions

Specific to the CSS Keyframe Animation Generator. Broader questions about this category are answered on the category page.

The default fill mode returns it to its unanimated state. Set forwards to hold the last keyframe.
Set direction to alternate, so it runs forwards then backwards. A loop whose end differs from its start will otherwise snap each time round.
Readers can ask their system for less movement, often because motion makes them unwell. That block honours the request and costs almost nothing.
transform and opacity. Both avoid recalculating layout, where animating width, height, top or left forces that work on every frame.
A transition runs between two states when something changes. An animation runs on its own through keyframes, and can loop.

Subscribe to receive notifications about new tools, features, and productivity tips.