Open In App

How to create a moving div using JavaScript ?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
1 Like
Like
Report

In this article, we will learn to create a moving HTML div using JavaScript. The div will move left to right using HTML, CSS, and JavaScript

Approach:

  • We have to create an HTML div and add some CSS to the div using a glass ball.
  •  In CSS, we add some background-color to the body and give some height, width, and color to the div.
  • Now we will add margin-left to the div using JavaScript. So it will move left to right.
  • In JavaScript, we grab the div using the id name. And after some interval of time, we will add margin-left to the div.

Example: In this example, we are using the above-explained approach.

Output:


Next Article

Similar Reads