Today, I wanted to mess around with something visual, so I thought, why not try making a pendulum animation? I’ve always been fascinated by how these things swing back and forth, so I decided to give it a shot.

First, I needed a plan. I figured I’d use some basic HTML for the structure, CSS for styling, and a bit of JavaScript to handle the animation. I started by creating a simple HTML file.
I sketched out a really basic structure: just a container div, a rod, and the pendulum bob. I didn’t want to overcomplicate things, so I just kept it super minimal.
Next up was the styling, my favorite part! I opened up a CSS file and started defining some looks. I wanted the container to be centered, so I used the usual flexbox tricks for that. I gave the rod a simple, thin, black appearance, and made the bob a nice, round, red circle. Nothing fancy, just enough to make it look like a pendulum.
Then came the JavaScript, which I admit, always feels a little tricky. I needed a way to make the pendulum swing, so I started with the obvious: the animate()
function, which is the best way to make it! I created a few keyframes to move the bob back and forth, changing the rotation angle gradually.
- Start: 0 degrees (centered)
- Middle: 30 degrees (swinging right)
- End: -30 degrees (swinging left)
I played around with the timing a bit, testing different durations and easing functions, trying to get a smooth, natural-looking swing, but it still looks a bit basic.

Finally I was done, and I’m quite proud of it!