October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

CSS Animations: A Practical Tutorial

Create a CSS keyframe animation, adjust its timing and repetition, and provide a reduced-motion alternative with a complete example.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A CSS keyframe animation needs two things: an @keyframes rule that describes the element’s visual states, and an animation declaration that tells the browser how to run those states. The example below fades a card into place, explains how to adjust its timing and repetition, and includes a reduced-motion alternative.

Build a basic CSS keyframe animation

Save this as an HTML file and open it in a browser. The card starts slightly lower and transparent, then moves into place while becoming visible.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>A CSS keyframe animation</title>
  <style>
    .card {
      max-width: 24rem;
      margin: 3rem auto;
      padding: 1.5rem;
      border: 1px solid #ccd3df;
      border-radius: 0.75rem;
      font: 1rem/1.5 system-ui, sans-serif;
      animation-name: arrive;
      animation-duration: 700ms;
      animation-timing-function: ease-out;
      animation-iteration-count: 1;
      animation-fill-mode: both;
    }

    @keyframes arrive {
      from {
        opacity: 0;
        transform: translateY(0.75rem);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    @media (prefers-reduced-motion: reduce) {
      .card {
        animation: none;
        opacity: 1;
        transform: none;
      }
    }
  </style>
</head>
<body>
  <main>
    <article class="card">
      <h1>Welcome</h1>
      <p>This card fades in and moves into place.</p>
    </article>
  </main>
</body>
</html>

What the keyframes describe

The @keyframes arrive rule names a sequence, arrive, and specifies the styles at its beginning and end. from means 0% of the animation; to means 100%. The browser interpolates between those states. You can add intermediate waypoints, such as 50%, when the motion needs a change of direction or pace.

Here, opacity changes from transparent to visible, while transform changes the vertical position. The element’s content remains present; the animation changes how it is presented.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What configures the sequence

The declarations on .card control how the named sequence runs. Keeping them as longhand properties makes each setting explicit:

  • animation-name: arrive selects the keyframes rule.
  • animation-duration: 700ms sets one run’s length.
  • animation-timing-function: ease-out makes the change progress quickly at first and slow toward the end.
  • animation-iteration-count: 1 runs it once.
  • animation-fill-mode: both applies the first keyframe’s styles during any delay and retains the final keyframe’s styles after the run.

Control timing, repetition, and playback

Start with duration and easing: duration determines how long a run takes, and the timing function determines how progress is distributed over that time. The remaining settings are useful when an effect needs a pause, repetition, reversal, or explicit playback control.

Duration and delay

Use animation-duration for the run time and animation-delay for the wait before it begins. In the animation shorthand, the first time value is the duration and the second is the delay. If duration is omitted, it defaults to 0s, so there is no visible animation.

Timing function

animation-timing-function controls the rate of change, not the keyframe states. Common choices include linear for steady progress, ease for a gradual start and finish, and ease-in or ease-out to emphasize one end of the motion. Choose the curve to suit the effect rather than using it as a substitute for a sensible duration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Iteration count and direction

animation-iteration-count accepts a number such as 1 or 3, or infinite for a repeating loop. Use an infinite loop sparingly, especially for decorative motion that continues while someone is reading.

animation-direction sets the direction of successive iterations. Its values include normal, reverse, alternate, and alternate-reverse. For example, alternate runs forward, then backward on the next iteration.

Fill mode and play state

animation-fill-mode controls whether keyframe styles apply outside the active run: none applies no fill, forwards retains the ending state, backwards applies the starting state during a delay, and both combines the latter two behaviors.

animation-play-state can be running or paused. It is useful when a page needs to pause an ongoing animation, for example in response to a user control. It does not change the keyframes themselves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use shorthand once the settings are clear

The example’s animation settings can be condensed into shorthand:

.card {
  animation: arrive 700ms ease-out 1 both;
}

This gives the name, duration, timing function, iteration count, and fill mode. The shorthand is compact, but longhand properties are often easier to maintain when a sequence has a delay, direction, or other less familiar setting. When writing multiple animations, separate each animation’s shorthand with a comma.

Respect reduced-motion preferences

The example uses @media (prefers-reduced-motion: reduce) to remove the decorative entrance animation for people whose operating-system or browser settings request reduced motion. It also sets the card’s opacity and transform to their visible, resting values so the content does not depend on the animation to appear.

Apply this preference to nonessential movement while preserving the page’s information and function. Avoid a blanket rule that removes motion without checking what it communicates: if movement is essential to understanding a change, provide a clear alternative cue. MDN’s guidance on CSS animations discusses users’ expectations around reducing nonessential motion, including motion triggered by interaction. W3C WAI’s C39 technique provides an example related to WCAG 2.3.3; W3C describes techniques as examples rather than mandatory implementation methods.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Blank Flip Book Paper with Holes - 240 Sheets (480 Pages) Flipbook Animation Paper : Works with Flip Book Kit Light Pads: for Drawing, Sketching Supplies/Comic Book Kit - Drawing Paper Animation Kit
  • Complete animation paper set … A great animation starter kit! Our 240 sheet (480 pages) flipbook paper with holes is quality 4.5inch x 2.5inch 120 gsm flippable paper and binding screws!
  • Perfect starter kits ... No more making your own flipbooks with scraps and staples. Our kits come with 2 sizes of binding screws, allowing you to trace and make flipbooks of many different sizes!
  • Individual pages ... Creating your own movies and animation has never been easier. No more limits on your animations that sewn binding books give you - With individual pages YOU get to decide!
  • Tracing made easy ... With our beautiful thick individual pages it is much easier to use with a light source, such as flip book light pads (not included) to trace your animations
  • Easy drawing ... No more spiral binding or pesky sewn book spines getting in your way. Our sketch pad paper is individual and free, just like your stop motion animations
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose CSS or script-driven animation

Approach Where the sequence is authored Useful when Reduced-motion consideration
CSS keyframe animation CSS, using @keyframes and animation properties The effect is a declarative visual sequence that can be described with styles. Add an appropriate prefers-reduced-motion treatment in CSS.
Script-driven animation, including the Web Animations API JavaScript The task benefits from programmatic control over playback or animation behavior. Account for the user’s motion preference in the script or the surrounding design.

CSS is a straightforward fit for self-contained effects whose states and timing belong in styling. Consider JavaScript or the Web Animations API when the application needs programmatic control. There is no universal performance winner: MDN describes opportunities for browser-side optimization of browser-controlled animations, including reduced update work for animations in hidden tabs, but that is not a guarantee that CSS is always faster than JavaScript.

Common problems and fixes

  • Nothing appears to animate: Confirm that animation-name exactly matches the name after @keyframes, and that duration is greater than zero. An omitted duration defaults to 0s.
  • The element stays transparent: Check that the final keyframe sets the intended visible state. If the animation should retain its ending styles, use an appropriate fill mode such as forwards or both.
  • The effect starts later than expected: Check for an animation-delay declaration, including a second time value in the shorthand.
  • The motion runs indefinitely: Look for infinite in the iteration count and replace it with a finite count if looping is not intended.
  • The reduced-motion rule has no effect: Verify the media query spelling and that the declaration targets the animated element. Test with the device or browser preference set to reduce motion; otherwise, the query may not match.
  • The animation runs but looks abrupt: Review both the duration and timing function. A timing curve changes the pace between states, while duration changes the total run time.

Or skip the browser setup

If your next step is capturing a screenshot of a page that contains your animation, ScreenshotNeo can return an image or PDF with one GET request. It is a screenshot API and MCP server, not a way to author or run CSS animations; the page must already be available at the URL you capture.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; each of those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month, with no card required.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.