Click Ripple Effect Button Template
Add dynamic, tactile feedback to your buttons with this cool click ripple effect.
Inspired by Google's Material Design, this effect creates a circle that ripples out from the exact point of a user's click, providing an engaging and modern interaction.

About the Click Ripple Effect Button
The ripple effect is a popular micro-interaction that provides immediate and tangible feedback for a click or tap. It confirms to the user not only that their action was registered, but precisely *where* it was registered. This template achieves the effect with a combination of CSS and JavaScript: the JavaScript detects the click location and creates the ripple element, while CSS handles the element's appearance and animation.
Features
- Dynamic Ripple Animation: The ripple originates from the cursor's position, making every click feel unique and responsive.
- Self-Contained and Reusable: The JavaScript is designed to work on any element that has the specified class name (
ripple-btn-1
). - Smooth CSS Animation: The expanding circle and fade-out effects are handled by a CSS
@keyframes
animation for smooth performance. - Accessible Foundation: Built on a semantic
button
element with a standard focus style.
Code Breakdown
The CSS sets the button's position
to relative
and overflow
to hidden
, which is required in order to contain the ripple. The ripple itself is a span
element that is created dynamically by JavaScript. It is styled to be a circle and is positioned absolutely within the button.
The JavaScript attaches a click event listener. When a click occurs, it calculates the cursor's coordinates relative to the button, creates a new element, sets its position using the calculated coordinates, and appends it to the button. The CSS animation then takes over. After the animation completes, the script removes the
span
from the DOM to keep the page clean.
Code
Here is the complete HTML, CSS, and JavaScript for the click ripple effect button.