October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Create and Capture Infinite CSS Animations

Set an animation to repeat with CSS, then use Playwright to capture motion or pause and seek to a specific frame.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set animation-iteration-count: infinite to make a CSS animation repeat. To capture a particular frame reliably, pause the browser animation and set its currentTime before taking the screenshot; letting it run captures whichever phase happens to be visible at that instant.

How to make a CSS animation loop forever

Define the animation’s visual states in a named @keyframes rule, then apply it to an element. The iteration count defaults to 1; setting it to infinite makes the sequence repeat indefinitely. See MDN’s animation-iteration-count reference and its guide to using CSS animations.

.pulse {
  animation: pulse 1.2s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

The shorthand values here specify the animation name, duration, easing, iteration count, and direction. alternate plays each cycle in the opposite direction from the previous one, producing a back-and-forth pulse. Leave it out if the reverse movement is not part of the intended effect. The animation shorthand also supports delay, fill mode, play state, and timeline; omitted components use their initial values.

Make the loop feel seamless

An infinite iteration count repeats the animation, but does not guarantee a visually seamless join. Check that the final rendered state connects naturally to the next cycle’s first state. If the reset is visible, adjust the keyframes or use a direction such as alternate when reversing the motion suits the design.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Capture a live animation or a chosen frame with Playwright

For a quick screenshot of the page in motion, allow animations to continue. The image records the phase visible when the screenshot is taken, so repeated runs can show different frames. Playwright documents the screenshot options in its Page screenshot API.

await page.screenshot({ path: 'animation.png', animations: 'allow' });

Why disabling animations may show the first frame

animations: 'disabled' is not a “freeze wherever it is now” setting. Playwright cancels infinite animations to their initial state for the screenshot and plays them again afterward. Screenshot assertions also default to disabled animation handling and wait for two consecutive identical screenshots, which can cause a moving scene to be reset rather than captured mid-cycle. See Playwright’s screenshot documentation and its visual comparison documentation.

Pause and seek to a repeatable point

For a deliberate still, select the relevant CSS animation, pause it, and set its time in milliseconds before taking the screenshot. Document.getAnimations() returns animations currently in effect, including CSS animations, transitions, and Web Animations; pause() suspends playback, and currentTime reads or sets its time. The references are getAnimations(), pause(), and currentTime.

// Run after the page has started the target CSS animation.
await page.evaluate(() => {
  const target = document.querySelector('.pulse');
  const animation = target?.getAnimations().find(
    (item) => item.animationName === 'pulse'
  );
  if (!animation) throw new Error('Target animation was not found');
  animation.pause();
  animation.currentTime = 600; // midpoint of the 1.2-second sample cycle
});

await page.screenshot({ path: 'animation-frame.png', animations: 'allow' });

The example assumes the animation has started and uses the sample’s 1.2-second duration, making 600 ms its midpoint. Change the time to the desired point. If several animations are active, target the correct element and animation name rather than pausing all of them. Allowing animations in the screenshot call avoids Playwright’s disabled-animation behavior after you have deliberately paused the chosen one.

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

Capture an animated GIF or video

A screenshot produces a still image, not an animated export. For a GIF or video, record or render a complete cycle using a workflow suited to the output format, then check whether the first and last frames join cleanly in the intended player. CSS and Playwright’s screenshot controls establish how to loop and capture a still; they do not prescribe a particular GIF or video encoder.

Respect reduced-motion preferences

Motion can be uncomfortable or harmful for some people, including those affected by vestibular disorders, epilepsy, migraine, scotopic sensitivity, or cognitive concerns. MDN recommends providing a way to pause or disable motion and respecting the reduced-motion preference. Keep essential content understandable without animation; see MDN’s animation accessibility guidance.

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

For user-facing motion, consider a visible pause control as well. A system preference and an in-page control are complementary: one honors a user’s general setting, while the other lets them stop this particular animation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo can return a screenshot in one GET request. Its clean-shot steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. It also has an MCP server with screenshot, page-info, and PDF tools for AI agents.

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

For example, this captures a still of the page at the instant it is rendered; it does not seek an infinite animation to a chosen frame. For a repeatable animation frame, use the Playwright pause-and-seek method above.

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

See the ScreenshotNeo API documentation for request options. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan.

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

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

Frequently Asked Questions

Can I use `animation-iteration-count: infinite` without a duration?

A duration controls how long a cycle takes; choose one that fits the motion. The CSS shorthand uses initial values for components you omit.

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

Does Playwright’s `animations: ‘allow’` make a screenshot deterministic?

No. It leaves the animation running, so timing can change which frame appears. Pause and set `currentTime` when the frame must be repeatable.

Does a screenshot save an infinite animation as a GIF?

No. A screenshot is a still image; an animated deliverable requires a separate recording or rendering workflow.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.