Skip to content
HTML to Image & Video

How to convert a CSS animation to video

Screen recording works, but it drops frames. These methods produce smooth, correctly timed video from CSS keyframes and transitions.

Updated · 7 min read

CSS animations run in real time on the screen, which makes them hard to turn into a video file. If you simply screen record, any hiccup in rendering becomes a dropped frame. The better approach is to control time yourself, capture each frame at an exact timestamp, and then assemble the frames.

Method 1: Screen recording

The simplest option is to play the animation and record the screen or a browser tab. It needs no code, but quality depends on your machine, frame pacing is not exact, and the loop point is hard to cut cleanly. It is fine for a quick demo and a poor fit for polished output.

Method 2: Headless browser and ffmpeg

For exact output, drive a browser from a script. Pause the animations, jump to a time, take a screenshot, and repeat for every frame. Then let ffmpeg turn the numbered images into a video.

// In the page, step every animation to a specific time (milliseconds)
document.getAnimations().forEach((animation) => {
  animation.pause();
  animation.currentTime = timeMs;
});
ffmpeg -framerate 30 -i frame%04d.png -pix_fmt yuv420p out.mp4

The Web Animations API call above works for CSS animations and transitions, because they appear in the document animation list. Animations driven by your own JavaScript timers are not covered, so you would need a deterministic clock for those.

Method 3: Frame-accurate recording in the browser

You can do the same thing without a server. Step the animations to each timestamp, snapshot each frame, then play the frames onto a canvas at the target frame rate while the MediaRecorder API records the canvas stream. Because the frames are rendered first, the final timing is exact even if rendering each frame is slow.

const stream = canvas.captureStream(0);
const recorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
recorder.start();

// draw frame i on the canvas, then push it to the stream
stream.getVideoTracks()[0].requestFrame();

This is how the converter on this site works. It records WebM in most browsers and MP4 where the browser can record it natively.

Tips for a clean result

  • Make the video length equal to one full loop of the animation so it repeats without a jump.
  • Use even width and height values, because many video encoders require them.
  • Lower the frame rate or frame size if memory runs out. 24 or 30 frames per second is enough for most motion graphics.
  • Keep the browser tab visible while a real-time recording step runs, since background tabs are throttled.

Convert your CSS animation to video now

Open Animation to Video

More guides