HG WEB STUDIO

Filed in: ,

Neon Button with CSS Hover Effects

Updated on: June 14, 2024

Table of Contents

In this post, I’ll walk you through how to create a neon button with a double border hover effect so you can easily add it to your web designs and Elementor.

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

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

CSS Neon Button Demo

See the Pen Neon Button Double Border 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">Click Me</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 ‘.neon-btn’.

First, let’s create its normal state.

/* button in its normal state */
.neon-btn {
  position: relative;
  padding: 20px 30px;
  background: transparent;
  border: 3px solid #f3eaff;
  border-radius: 50px;
  font-family: "Nunito Sans", sans-serif;
  font-size: 16px;
  text-decoration: none;
  color: #fff;
  box-shadow: 0 0 7px 0 #9013fe, 0 0 5px 2px #d64eff, inset 0 0 7px 0 #9013fe, inset 0 0 5px 1px #d64eff;
}

Next, let’s create the before pseudo element. The before element creates the second neon border that appears on hover.

/* before pseudo-element */
.neon-btn::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border-radius: 50px;
  transition: all 200ms ease-in-out;
}

Lastly, we need to create the hover state for the pseudo-element. The before element begins as the same height and width as the main button but grows 16px on all sides when hovered.

/* before hover state */
.neon-btn:hover::before {
  top: -9px;
  left: -9px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: 1px solid #f3eaff;
  box-shadow: 0 0 7px 0 #9013fe, 0 0 5px 2px #d64eff, inset 0 0 7px 0 #9013fe, inset 0 0 5px 1px #d64eff;
}

How to add the neon button in Elementor

Demo of neon 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 padding, 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 #fff.
  3. Change the background color to transparent. The background of the page should be something dark, like #111.
  4. Set the border type to solid 2px #fff.
  5. Set the border-radius to 50px.
  6. Add padding to increase the size of your button, if necessary. I used 16px for top and bottom and 24px for left and right.

Lastly, in the button widget advanced tab:

  1. Change the align self property to start, center, or end. I’m using start.
  2. In the CSS classes box, type in your class selector. I used ‘neon-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.

Neon button 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).

/* button in its normal state */ 
.neon-btn {
  position: relative;
  border-radius: 50px;
  box-shadow: 0 0 7px 0 #faaffa, 
              0 0 5px 1px #fe68e5, 
        inset 0 0 7px 0 #faaffa, 
        inset 0 0 5px 1px #fe68e5;
}

2. Next, create the pseudo-element in its normal state.

/* before pseudo-element */
.neon-btn::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border-radius: 50px;
  transition: all 200ms ease-in-out;
}

3. Lastly, we need to create the hover state.

/* before pseudo-element hover state */
.neon-btn:hover::before {
  top: -8px;
  left: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: 1px solid #fff;
  box-shadow: 0 0 7px 0 #faaffa, 
              0 0 5px 1px #fe68e5, 
        inset 0 0 7px 0 #faaffa, 
        inset 0 0 5px 1px #fe68e5;
}

Publish your changes.

Step 3: Checking for mobile responsiveness in Elementor

Image of neon button on mobile device with website in responsive mode

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 Neon Button with CSS Effects in Elementor

/* button in its normal state */ 
.neon-btn {
  position: relative;
  border-radius: 50px;
  box-shadow: 0 0 7px 0 #faaffa, 
              0 0 5px 1px #fe68e5, 
        inset 0 0 7px 0 #faaffa, 
        inset 0 0 5px 1px #fe68e5;
}

/* before pseudo-element normal state */
.neon-btn::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border-radius: 50px;
  transition: all 200ms ease-in-out;
}

/* before pseudo-element hover state */
.neon-btn:hover::before {
  top: -8px;
  left: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: 1px solid #fff;
  box-shadow: 0 0 7px 0 #faaffa, 
              0 0 5px 1px #fe68e5, 
        inset 0 0 7px 0 #faaffa, 
        inset 0 0 5px 1px #fe68e5;
}

Button inspiration found here.

Table of Contents

Search

Browse by Category

Leave a Reply

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