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.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
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: arriveselects the keyframes rule.animation-duration: 700mssets one run’s length.animation-timing-function: ease-outmakes the change progress quickly at first and slow toward the end.animation-iteration-count: 1runs it once.animation-fill-mode: bothapplies 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.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Rank #2
- Used Book in Good Condition
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.
Recommended Free Tools
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.
Rank #4
- 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
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-nameexactly matches the name after@keyframes, and that duration is greater than zero. An omitted duration defaults to0s. - 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
forwardsorboth. - The effect starts later than expected: Check for an
animation-delaydeclaration, including a second time value in the shorthand. - The motion runs indefinitely: Look for
infinitein 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.
Quick Recap
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.




