HG WEB STUDIO

Filed in: ,

3D Button with CSS Shadow Hover Effect

Updated on: June 14, 2024

Table of Contents

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

This 3D button is perfect for modern web designs that prioritize creative and unique aesthetics. I used Nixie One, a Google font included in the Elementor plugin. Some other fonts that would work well with this button include Inconsolata, Mulish, and Roboto.

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

CSS 3D Button Demo

See the Pen 3D Button Shadow Effect 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">read more <span>→</span></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 arrow is wrapped in a span element so we can style it separately. You could also use an SVG or icon here.

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;
  justify-content: center;
  align-items: center;
  gap: 10px; /* gap size btw text and arrow */
  height: 64px;
  width: 180px;
  background-color: #fefefe;
  color: #454241;
  font-family: "Nixie One", system-ui;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  text-decoration: none;
  border-radius: 16px;
  box-shadow: -6px 8px 10px rgba(130, 117, 121,0.1),0px 4px 4px rgba(130, 117, 121,0.2); 
}

/* arrow */
span {
  font-size: 24px;
}

Next, let’s create the pseudo-element. In the normal state, the pseudo-element is larger than the button by 20px on all sides. It’s also positioned behind the button with the negative z-index.

/* pseudo-element */
.custom-btn::before {
  content: "";
  position: absolute;
  width: calc(100% + 20px);
  height: calc(100% + 20px);
  background-color: #fff5f2;
  border: 1px solid #f4dbd1;
  border-radius: 26px; /* outter border radius = inner border radius + distance, so border-radius = 16px + 10px */
  overflow: hidden;
  z-index: -1;
}

Now we need a hover state for the ::before pseudo-element. On hover, a reduced brightness filter is applied to the background color.

/* ::before button hover */
.custom-btn:hover::before {
  filter: brightness(.98);
}

Lastly, we need an active state to create a visual indication that the button was clicked. The button’s shadow is removed and the pseudo-element’s brightness filter is increased back to 1 when clicked.

/* button active state */
.custom-btn:active {
  box-shadow: none;
}

/* button active state for ::before pseudo-element */
.custom-btn:active::before {
  filter: brightness(1);
}

How to add the 3D 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.

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 #1d1d1d.
  3. Choose the background color. I’m using #ffffff.
  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 20px for top and bottom and 50px 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: margin-left, position, display, justify-content, and align-items, border-radius, box-shadow, and z-index. We’ve already set some of the styling using the button widget; however, we need to set the display properties so the pseudo-element sits properly and add the box-shadow.
/* button in its normal state */ 
.custom-btn {
   margin-left: 10px; /* For left-aligned buttons */ 
   position: relative;
   display: flex;
   justify-content: center;
   align-items: center;
   border-radius: 50px;
   box-shadow: -6px 8px 10px rgba(130, 117, 121,0.1),0px 4px 4px rgba(130, 117, 121,0.2);
   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, background-color, border, border-radius, overflow, and z-index.
/* button before */
.custom-btn::before {
   content: "";
   position: absolute;
   width: calc(100% + 20px);
   height: calc(100% + 20px);
   background-color: #F8C3D052;
   border: 1px solid #F8C3D0;
   border-radius: 66px;
   overflow: hidden;
   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 property: filter.
/* button hover before */
.custom-btn:hover:before {
   filter: brightness(.98);
}

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

  • Set the selector .custom-btn with :active.
  • Inside the curly brackets, set the following property: box-shadow.
  • set the selector .custom-btn:active with the ::before pseudo-element.
  • Inside the curly brackets, set the following property: filter.
/* button active state */
.custom-btn:active {
   box-shadow: none;
}

.custom-btn:active:before {
   filter: brightness(1);
}

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 3D Button with Hover Effect in Elementor

/* button in its normal state */ 
.custom-btn {
   margin-left: 10px; /* For left-aligned buttons */ 
   position: relative;
   display: flex;
   justify-content: center;
   align-items: center;
   border-radius: 50px;
   box-shadow: -6px 8px 10px rgba(130, 117, 121,0.1),0px 4px 4px rgba(130, 117, 121,0.2);
   z-index: 1;
}

/* button before */
.custom-btn::before {
   content: "";
   position: absolute;
   width: calc(100% + 20px);
   height: calc(100% + 20px);
   background-color: #F8C3D052;
   border: 1px solid #F8C3D0;
   border-radius: 46px;
   overflow: hidden;
   z-index: -1;
}

/* button hover before */
.custom-btn:hover:before {
   filter: brightness(.98);
}

/* button active state */
.custom-btn:active {
   box-shadow: none;
}

.custom-btn:active:before {
   filter: brightness(1);
}

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 *