VOOZH about

URL: https://www.geeksforgeeks.org/css/multiple-pendulum-animation-using-css/

⇱ Multiple Pendulum Animation using CSS - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Multiple Pendulum Animation using CSS

Last Updated : 23 Jul, 2025

In this article, we will see the creation of the Multiple Pendulum Animation using HTML & CSS. To accomplish this task, we will use two elements, i.e. for creating the shadow and knob for the Pendulum, we will use CSS :after and :before selectors. We will follow the below approach to create the Multiple Pendulum Animation.

Approach:

  • First, create an HTML snippet for creating the structure of the pendulum.
  • As pendulum elements, create two elements one div element with the pendulum-base class name, and within the pendulum-base, create multiple pendulum elements. Here we're creating 15 pendulums inside my pendulum-base class. Now, start applying CSS for animation.
  • Apply global CSS with the help of the * selector so that everything works correctly.
  • Apply styling to the pendulum-base class. For that, we can create a large plain rectangle width of 500px and height of 300px and give a border-top of 3px to the rectangle, so that it looks like the base of the pendulum structure.
  • Now add CSS for the pendulums. For that, we're applying one common CSS to all pendulums elements, for that, we can apply CSS for separate pendulums with the help of :nth-of-type.
  • For creating the knob, we use :before selector with a width of 15px and height of 15px with background: radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%) to create a sphere and its realistic color.
  • For adding the shadow, we will use :after selector with background: rgba(0, 0, 0, 0.3) and filter: blur(5px) which makes it looks like a shadow.
  • Now, creates an animation that is responsible for the pendulum swinging back and forth. It rotates the thread element around its midpoint using the transform property.
  • At the start and end of the animation (0% and 100%), the element is rotated 25degrees to the right and translated horizontally to the left by 50% of its own width using the transform property.
  • At the halfway point of the animation (50%), the element is rotated 25 degrees to the left and translated horizontally to the left by 50% of its own width.

Example: This example illustrates the Multiple Pendulum Animation using HTML & CSS.

Output:

Comment