How to make Animated Click Effect using Tailwind CSS & JavaScript ? Last Updated : 16 Apr, 2024 Comments Improve Suggest changes Like Article Like Report It refers to the technique of implementing animations that respond to user clicks, utilizing the Tailwind CSS for styling and layout, and JavaScript for adding dynamic behavior to the elements. This enhances user engagement and improves the overall user experience of the websites. Table of Content Using Tailwind ClassesUsing Anime.js libraryUsing Tailwind ClassesAnimation Class: Added Tailwind CSS utility class animate-bounce to the button element which creates a bouncing effect when clicked.JavaScript: Utilized JavaScript to add and remove the animation class. The class is added on click, triggering the animation, and removed after 500ms, ensuring the animation only occurs once per click.Example: The below code uses Tailwind classes with JavaScript to animate the button on click. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> How to Make Animated Click Effect using Tailwind CSS and JavaScript </title> <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"> </head> <body class="flex justify-center items-center h-screen bg-gray-100"> <button id="animatedButton" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-4 px-8 rounded transition-all duration-300 transform hover:scale-105"> Click Me </button> <script> const button = document. getElementById('animatedButton'); button.addEventListener('click', () => { button.classList.add('animate-bounce'); setTimeout(() => { button.classList. remove('animate-bounce'); }, 500); }); </script> </body> </html> Output: Using Anime.js libraryJavaScript Animation Library: Included the Anime.js library via CDN to enable advanced animations.Enhanced Animation: Expanded the animation by incorporating additional properties such as rotate. The button now rotates by 1 turn during the animation sequence.Anime.js Configuration: Defined multiple scale values to create a more dynamic scaling effect. The button scales up to 1.2 times its original size smoothly over 400ms, then returns to its original size.Example: The below code uses Anime.js library to animate the button on click. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> How to Make Animated Click Effect using Tailwind CSS and JavaScript </title> <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"> </head> <body class="flex justify-center items-center h-screen bg-gray-100"> <button id="animatedButton" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-4 px-8 rounded transition-all duration-300 transform hover:scale-105"> Click Me </button> <script src= "https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"> </script> <script> const button = document. getElementById('animatedButton'); button.addEventListener('click', () => { anime({ targets: button, scale: [ { value: 1, duration: 100, easing: 'easeInOutQuad' }, { value: 1.2, duration: 400, easing: 'easeInOutQuad' }, { value: 1, duration: 100, easing: 'easeInOutQuad' } ], rotate: { value: '1turn', easing: 'easeInOutSine' } }); }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to make Animated Click Effect using Tailwind CSS & JavaScript ? D djnanasatkx0l Follow Improve Article Tags : Tailwind CSS Tailwind CSS-Questions Similar Reads How to make a CTA Animation with Tailwind CSS ? To enhance the engagement level of your website's Call-to-Action (CTA) elements we use Tailwind CSS utility classes. By directly customizing transition effects with Tailwind CSS, you can effortlessly introduce captivating animation effects to your CTAs, improving user interaction and overall user ex 2 min read Underline Hover Animation Effect using Tailwind CSS The Tailwind CSS underline animation is a visual effect that can be added to any text or heading or a specific word in the web page using the Tailwind CSS utility framework. The basic function of this effect is this creates an underline animation from left to right with a smooth transition, in simpl 3 min read How to add scale animation on hover using Tailwind CSS in React ? In this article, we'll see how to add scale animation on hover using tailwind CSS in a ReactJS app. The hover effect appears when a user positions the cursor over an element. In tailwind CSS, the scale utility class helps in getting the zoom effect over an element. PrerequisitesReact JSTailwind CSSA 3 min read How to Create Animated Loading Button using Tailwind CSS? An Animated Loading Button is a button that displays a loading spinner or animation to indicate an ongoing process, such as form submission. Using Tailwind CSS, you can create this by combining utility classes for styling and animations to visually enhance the button during loading. Table of Content 2 min read How to Make Floating Card Effect in Tailwind CSS? Floating card effect using Tailwind CSS is fun to make and explore. It is basically all about using the classes of Tailwind CSS to create cards when hovered upon have a floating effect, such that they are replaced from their position, either get transformed, or move up or down in their positions. we 2 min read How to Modify Hover Effect using Tailwind CSS ? In Tailwind CSS, the term "modify hover" refers to changing the styles that are applied to an element when it is hovered over. With Tailwind CSS "hover" variation, you can quickly apply particular utility classes and custom classes to control how components appear when you hover over them, giving yo 3 min read How to Change Image on Hover using Tailwind CSS? One common effect is changing an image when the user hovers over it. We use Tailwind CSS, a utility-first CSS framework, to accomplish this without any additional JavaScript logic for the hover effect. By utilizing Tailwind's built-in classes we can create smooth transitions between two images where 2 min read How to Create Parallax Effect in Tailwind CSS ? A parallax website includes fixed images in the background that are kept in place and the user can scroll down the page to see different parts of the image. If you use the parallax effect on our page then it helps the user to interact with the page. PreviewCreating Parallax Effect in Tailwind CSS At 3 min read How to use CSS Animations with Tailwind CSS ? Tailwind CSS classes are used to style elements and apply animations effortlessly. Utilize Tailwind's animation utility classes to add dynamic visual effects. Combine Tailwind CSS with custom CSS animations for versatile and engaging web designs. Table of Content Tailwind CSS Animation Utility Class 3 min read How to create a marquee effect using CSS ? In this article, we will be creating the marquee effect by using HTML and CSS. This effect can be created by using the <marquee> tag in HTML, but we will not use this tag as it is not widely used nowadays. We will create and design a marquee effect by using the CSS classes and styling properti 2 min read Like