DEV Community

Cover image for How to make an animated like button | HTML, CSS, JavaScript
Pedro Romão
Pedro Romão

Posted on

7 2

How to make an animated like button | HTML, CSS, JavaScript

There are many like animations available on the internet, but this is one of my favorites. It's simple, easy to apply and different from what we see out there.

In this article, we will create an animated like button that you can use in your projects.

Let's first look at what are we building, feel free to press the button and see the animation happening :):

Explaining the code

The "item--bg" class is the active state color that will be appear when the user press the "Click me" button. At the beginning, it will be invisible to the user and will appear only when the "active" class is with the "item" element:
Like state

The shake animation will happen only when the "shake" class is with the "item" element:
Shake animation

When the user press the "Click me" button, the JavaScript code will be called adding the "active" and "shake" class to the "item" element and removing the "shake" class after 2 seconds:
Pressing the button

Thank you for reading, and let's connect!

Thank you for reading, and feel free to connect with me on Linkedin and check my Youtube channel.

And if you like my work and want to support me, you can buy me a coffee by clicking here.

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute and it's free.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay