CSS animation

A CSS animation makes an element change styles over time using keyframes, adding motion like fades, slides or loops without JavaScript.
Design
Created on
23.08.2026

Summarize this

A CSS animation makes an element change its styles over time, following a set of keyframes, to create motion such as fades, slides, pulses or loops. It runs directly in the browser without JavaScript, which makes it lightweight and smooth for interface effects.

Keyframes and the animation properties

An animation has two parts: a @keyframes rule that describes the styles at points from 0% to 100%, and an animation declaration that plays them on the element.

  • @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  • animation: fade 300ms ease-in-out;
  • Sub-properties: animation-duration, -timing-function, -delay, -iteration-count, -direction, -fill-mode.

Animation versus transition

Both add motion, but they are triggered and shaped differently.

AspectTransitionAnimation
TriggerNeeds a state change (hover, class)Can run on its own or on load
StepsTwo states, start and endMany keyframes
LoopingNoYes (iteration-count)
Best forHover and focus feedbackMulti-step or looping motion

Timing, iteration and fill

Beyond duration, a few properties shape how an animation feels. animation-iteration-count: infinite loops it, animation-direction: alternate plays it back and forth, and animation-fill-mode: forwards keeps the final state after it ends. The timing function (ease, linear, a custom cubic-bezier, or steps() for frame-by-frame) controls the pace.

Performance and accessibility

Animating transform and opacity is smooth because the browser can offload them to the GPU, while animating layout properties like width or top can cause jank. For accessibility, respect the prefers-reduced-motion setting so users who are sensitive to motion get a calmer experience.

CSS, JavaScript, Lottie or Rive

Use CSS for simple, decorative motion. Reach for JavaScript or a library like GSAP when you need complex sequencing or interactivity. For rich, designer-made vector animation, export from tools like Lottie or Rive and drop it into the page, keeping the CSS layer light.

CSS animation at BeBranded

At BeBranded we use motion with intent: subtle, performant animations that guide attention without slowing the page. For richer motion we combine CSS with tools like Lottie or Rive, as part of our design work.

FAQ

A CSS animation makes an element change styles over time following keyframes, creating motion like fades, slides or loops directly in the browser without JavaScript.
A transition animates one change between two states, usually on an interaction. An animation can define many steps and run on its own or loop. Use transitions for simple state changes, animations for multi-step motion.
Keyframes describe the styles an element should have at points along an animation, from 0 percent to 100 percent. The browser interpolates the styles between them.
They can be. Animating transform and opacity is smooth because the browser uses the GPU. Animating layout properties like width or top is heavier and can cause jank.
It is a user setting that signals a preference for less motion. Respecting it in CSS lets you reduce or remove animations for people who are sensitive to movement.
Use JavaScript, or a tool like GSAP, when you need complex sequencing, interactivity, or fine control that keyframes alone cannot express. For simple, decorative motion, CSS is enough.

Ready to boost your conversions?

Our team is here to understand your needs & work with you to create your next projects.
Get news, infos and resources.
Actionable tips delivered straight to your inbox.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.