Skip to content
Related Articles

Related Articles

How to create Frame by Frame Animation using CSS and JavaScript ?

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 28 Jul, 2021
Improve Article
Save Article

Frame by frame animation is a technique where a set of images are shown, one by one in a particular order, maintaining fixed time interval gaps between two consecutive images, to make an illusion of motion to the eyes. Now, in a more technical way, we can say that frame-by-frame animation is a technique where different frames appear, one after another, maintaining fixed time interval gaps in different frames to make the illusion of movement.

We can use the JavaScript setInterval() method to create a frame-by-frame animation. The setInterval() method is used to repeat a particular function at every given time interval, so it can be used in the frame-by-frame animation on the set of frames so that they appear to have fixed time interval gaps in between them.


setInterval(function, milliseconds);


  • function: The function that has to be executed.
  • milliseconds: It indicates the length of the time interval in milliseconds between each frame.



<!DOCTYPE html>
        img {
            height: 250px;
            width: 250px;
        .center {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 250px;
            height: 250px;
            border: 3px solid #73AD21;
            padding: 2px;
        var images = new Array()
        images = [
        setInterval("Animate()", 400);
        var x = 0;
        function Animate() {
            document.getElementById("img").src = images[x]
            if (images.length == x) {
                x = 0;
    <div class="center">
        <img id="img" src=
        <h3>Frame by Frame Animation</h3>


Animation of frames

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!