Ripple Button Effect Using Pure CSS
Original Source: https://1stwebdesigner.com/ripple-button-effect-using-pure-css/
Google’s Material Design guidelines introduced the ripple effect, a subtle animation that indicates user action. The ripple effect rapidly gained popularity in web design as a sophisticated visual feedback form that refines user interaction, particularly on buttons. Today, we’ll show you how to create a ripple button effect using nothing but pure CSS.
Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets
DOWNLOAD NOW
Building the Button
The basic structure of our button is quite simple. It’s a single line of HTML:
<button class="btn-ripple">CLICK ME</button>
This is a standard button element with a class btn-ripple attached to it, which will be our reference when we define the ripple effect in CSS.
Casting Ripples With CSS
/* Styling for the ripple button */
.btn-ripple {
border: none; /* Removing the default button border */
border-radius: 6px; /* Giving our button rounded corners */
padding: 12px 16px; /* Providing some padding around the button text */
font-size: 1.2em; /* Increasing the font size of the button text */
cursor: pointer; /* Changing the cursor to a hand icon when hovering over the button */
color: white; /* Making the button text color white */
background-color: #fa6e83; /* Setting the initial button background color */
outline: none; /* Removing the outline from the button */
background-position: center; /* Setting the position of the background image to center */
transition: background 1s; /* Adding a transition to the background color */
}
/* Defining the hover state */
.btn-ripple:hover {
background: #f94b71 radial-gradient(circle, transparent 1%, #f94b71 1%)
center/15000%; /* Creating a radial gradient background on hover */
}
/* Defining the active (clicked) state */
.btn-ripple:active {
background-color: #f97c85; /* Changing the button color when active */
background-size: 100%; /* Increasing the size of the background image */
transition: background 0s; /* Removing the transition from the background color */
}
Let’s break down the CSS setup:
The .btn-ripple class sets up the basic appearance of the button. The background-color is initially set to #FA6E83, a light color, and the background-position is centered to ensure our ripple effect starts from the middle of the button.
When you hover over the button, the :hover pseudo-class is activated. It changes the background to a radial gradient that’s centered where the pointer is located, simulating the ripple effect. The gradient starts as transparent (transparent 1%) and transitions to the button color (#F94B71 1%), creating a soft ripple effect.
Upon clicking the button, the :active pseudo-class takes effect. It changes the background-color to a darker shade (#F97C85) and expands the background-size to 100%, reinforcing the ripple effect. The transition for the background is also set to 0s, making the effect appear instantaneously when the button is clicked.
The Result
See the Pen
Pure CSS Ripple Button Effect by 1stWebDesigner (@firstwebdesigner)
on CodePen.0
Final Thoughts
We demonstrated a classic example of how simple CSS can be used to create appealing interactivity in a user interface. But as you strive to refine your UI, it’s critical to remember that each interface element might require different tweaks.
Consider the context in which your buttons are used. A button for submitting form data might benefit from a more subdued ripple effect, while a call-to-action button could be more prominent with a stronger one.
For more intricate animations or synchronizing with other UI events, JavaScript could be leveraged for more granular control. CSS provides a solid base for styling and basic animations, but JavaScript opens up more advanced possibilities.
And of course, customization is key. While we used specific colors for our ripple button here, feel free to experiment with colors, shapes, and transitions that align with your brand and design aesthetic.
Leave a Reply
Want to join the discussion?Feel free to contribute!