HG WEB STUDIO

Filed in: ,

Glass Morphism Button Hover CSS Effects

Updated on: June 14, 2024

Table of Contents

In this post, I’ll walk you through how to create this glass morphism button with a hover effect so you can use it in your web designs and Elementor.

This button is perfect for modern web designs that prioritize creative and unique aesthetics. I used Poppins, a Google font included in the Elementor plugin. Some other fonts that would work well with this button include Roboto, Oxygen, and Source Sans Pro.

25 Best Font Combinations for Elementor Websites svg of arrow pointing right

CSS Glass Morphism Button Demo

See the Pen Button Hover with Blur by Kate (@kate_hg123) on CodePen.

HTML Breakdown

I used the <a> element for this button, but you can swap it out for the <button> element. Each of these elements has different use cases.

Use Cases:

  • Use the button element when: You need a clickable element to trigger an action, like submitting a form, triggering JavaScript functions, or performing an action within the webpage.
  • Use the anchor element when: You need to create hyperlinks for navigation, whether it’s within the same webpage or linking to external pages.

HTML Code using the anchor element

<a href="#" class="custom-btn" role="link"><p>Hover Me</p></a>

To create a link that is visually styled as a button, we need to have the following attributes: href, class, and role.

  • href: Defines the destination link. Replace the ‘#’ with your link or anchor.
  • class: Defines the selector to target for styling.
  • role: Defines the purpose of the element for accessibility technologies like screen readers.

The text is wrapped in a p element so we can style it separately and make sure it stays forward with the z-index property.

Learn more about links at W3Schools.

HTML Code using the button element

<button id="my-btn" class="custom-btn" type="button">Submit</button>

To create a button, we need to have the following attributes: class, id, and type.

  • class: Defines the selector to target for styling.
  • id: Defines the selector to target for JavaScript functions or other element-specific styling and actions. Ids are more specific than classes and should only be used once, whereas classes can be used for multiple elements.
  • type: Defines the type of button and its intended action. There are three types: button, submit, and reset.

Learn more about buttons at W3Schools.

CSS Breakdown

To style our button, we need to target the element with the class selector we chose in the HTML. I’m using ‘.custom-btn’.

First, let’s create its normal state:

/* button in its normal state */
.custom-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 68px;
  background: #222;
  border-radius: 50px;
  font-size: 16px;
  font-family: "Poppins", sans-serif;
  font-weight: 500;
  color: #fff;
  letter-spacing: 3px;
  text-decoration: none;
}

Next, let’s create the pseudo-element. In the normal state, the pseudo-element is smaller than the button and positioned at the bottom right.

/* pseudo-element */
.custom-btn::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 35px;
  height: 35px;
  background: #ffffff15;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 50px;
  transform: translate(10px, 10px);
  transition: all 300ms ease-in-out;
}

Now we need a hover state for the text and the ::before pseudo-element. On hover, the glass morphism pseudo-element grows in size.

/* Button text hover */
.custom-btn:hover p {
  z-index: 1;
}

/* ::before button hover */
.custom-btn:hover::before {
  border-radius: 50px;
  transform: translate(-4px, -15px);
  height: 90%;
  width: 95%;
}

Lastly, we need an active state to create a visual indication that the button was clicked. The pseudo-element drops down along the Y-axis in the active state.

/* button active state for ::before pseudo-element */

.custom-btn:active::before {
    transform: translate(-4px, -4px);
    transition: 0ms;
}

How to add the Glass Morphism button in Elementor

To create this button in Elementor, I’m using the button widget instead of writing my own HTML code. We can write fewer lines of custom CSS by using some of the style settings available in the widget.

For this example, I’ve adjusted some of the properties to fit the styling of the web design, like the border radius, background color, and font. The background color of the button widget needs to be transparent.

Step 1: Add the button widget to your canvas and give it some basic styling

Navigate to the button widget content tab:

  1. Change the CTA text
  2. Add the button link

Then, in the button widget style tab:

  1. Change the typography to match your website (font family, font size, weight, etc.).
  2. Choose the text color. I’m using #ffffff.
  3. Change the background color to transparent.
  4. Set the border type to none.
  5. Set the border-radius to 50px.
  6. Add padding to increase the size of your button. I used 24px for top and bottom and 48px for left and right.

Lastly, in the button widget advanced tab:

  1. In the CSS classes box, type in your class selector. I used ‘custom-btn’.

Now let’s write our code.

Step 2: Write the custom CSS in the WordPress Customizer

You can also use the custom CSS area in the advanced tab of the button widget. I prefer keeping all my custom code in one place for better management.

In the WP customizer navigate to ‘Additional CSS’

1. Create the normal state (how it looks on the page without any user interaction)

  • Set the selector: .custom-btn {}.
  • Inside the curly brackets, set the following properties: position, display, justify-content, align-items, background-color, border-radius, and z-index.
/* button in its normal state */ 
.custom-btn {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #212121;
  border-radius: 50px;
  z-index: 1;
}

2. Next, create the normal state for the ::before pseudo element

  • Set the selector .custom-btn with ::before.
  • Inside the curly brackets, set the following properties: content, position, width, height, bottom, right, transform, background, backdrop-filter, border-radius, transition, and z-index. The backdrop-filter creates the blurred glass morphism effect.
/* ::before button in its normal state */
.custom-btn::before{
  content: '';
  position: absolute;
  width: 35px;
  height: 35px;
  bottom: 0;
  right: 0;
  transform: translate(10px, 10px);
  background: #ffffff15;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 38px;
  transition: all 300ms ease-in-out;
  z-index: -1;
}

3. Create the hover state for the ::before pseudo-element

  • Set the selector .custom-btn with :hover::before.
  • Inside the curly brackets, set the following properties: transform, height, and width. The transform property raises the pseudo-element along the Y-axis so it’s positioned above the button.
/* ::before button in its hover state */
.custom-btn:hover::before{
  transform: translate(-4px, -12px); /* You may need to adjust these numbers to fit the size of your button */
  height: 90%;
  width: 95%;
}

4. Create the active state (how the button looks on the page when a user clicks on it)

  • set the selector .custom-btn:active with the ::before pseudo-element.
  • Inside the curly brackets, set the following properties: transform and transition.

/* ::before button in its active state */
.custom-btn:active::before {
  transform: translate(-4px, -4px); /* You may need to adjust these numbers to fit the size of your button */
  transition: 0ms;
}

Publish your changes.

Step 3: Checking for mobile responsiveness in Elementor

Lastly, we need to check our code for mobile responsiveness.

In the Elementor editor, adjust the width of your button for tablet and mobile view using Elementor’s responsive settings.

Final Thoughts

Feel free to use my code as is, or play around with the different properties to create a button that fits your website aesthetic. Experiment with the colors and font, and make it yours!

Remember, if you experience any issues or have questions along the way, feel free to drop them in the comments below. I’d love to see your work, and I’m here to help!

Full CSS for Neumorphism Button Hover Effect in Elementor

/* button in its normal state */ 
.custom-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #212121;
  border-radius: 50px;
  z-index: 1;
}

/* ::before button in its normal state */
.custom-btn::before{
  content: '';
  position: absolute;
  width: 35px;
  height: 35px;
  bottom: 0;
  right: 0;
  transform: translate(10px, 10px);
  background: #ffffff15;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 38px;
  transition: all 300ms ease-in-out;
  z-index: -1;
}

/* ::before button in its hover state */
.custom-btn:hover::before{
  transform: translate(-4px, -12px);
  height: 90%;
  width: 95%;
}

/* ::before button in its active state */
.custom-btn:active::before {
  transform: translate(-4px, -4px);
  transition: 0ms;
}

My button was inspired by this button.

Table of Contents

Search

Browse by Category

Leave a Reply

Your email address will not be published. Required fields are marked *