HG WEB STUDIO

Filed in: ,

Button with 3D CSS Click Effects

Updated on: June 14, 2024

Table of Contents

In this post, I’ll walk you through how to create a 3D button with box-shadow effects so you can easily add it to your web designs and Elementor.

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

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

CSS 3D Button Demo

See the Pen 3D Button 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">Button</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.

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. We are giving the button some simple styling with a transparent background and black border.

/* button in its normal state */
.custom-btn {
  padding: 20px 44px;
  background-color: transparent;
  border: 1px solid #141211;
  border-radius: 50px;
  font-family: "Ubuntu Sans Mono", monospace;
  font-size: 24px;
  color: #141211;
  text-decoration: none;
  box-shadow: 0 0 0;
  transition: all 200ms;
}

Next, let’s create a hover effect. On hover, the box shadow appears and the button moves up 10px along the Y-axis.

/* hover effect */
.custom-btn:hover {
  transform: translateY(-10px);
  box-shadow: 0px 12px 1px #141211;
}

Lastly, we need an active state to create a visual indication that the button was clicked. The box-shadow disappears and the button moves 10px down along the Y-axis.

/* button active state */

.custom-btn:active {
  transform: translateY(10px);
  box-shadow: 0 0 0;
}

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 #141211.
  3. Change the background color to transparent (or whatever color you prefer).
  4. Set the border type to solid, the border width to 1px, and the border color to #141211.
  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 44px 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.

CSS code in WP customizer

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: border-radius, box-shadow, and transition.
/* button in its normal state */ 
.custom-btn {
  border-radius: 50px;
  box-shadow: 0 0 0;
  transition: all 200ms;
}

2. Next, create the hover state for button.

  • Set the selector .custom-btn with :hover{}.
  • Inside the curly brackets, set the following properties: transform and box-shadow.
/* button in hover state */
.custom-btn:hover {
  transform: translateY(-10px);
  box-shadow: 0px 12px 1px #141211;
}

3. Lastly, create the active state for button.

  • Set the selector .custom-btn with :active {}.
  • Inside the curly brackets, set the following properties: transform and box-shadow.
/* button in active state */
.custom-btn:active {
  transform: translateY(10px);
  box-shadow: 0 0 0;
}

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 padding or 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 Code for 3D Button with CSS Shadow Click Effects in Elementor


/* button in its normal state */ 
.custom-btn {
  border-radius: 50px;
  box-shadow: 0 0 0;
  transition: all 200ms;
}

/* button in its hover state */ 
.custom-btn:hover {
  transform: translateY(-10px);
  box-shadow: 0px 12px 1px #141211;
}

/* button in its active state */ 
.custom-btn:active {
  transform: translateY(10px);
  box-shadow: 0 0 0;
}

Table of Contents

Search

Browse by Category

Leave a Reply

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