Neumorphic Buttons with Icons Using CSS

Neumorphic Buttons with Icons Using CSS
Code Snippet:Neumorphic buttons
Author: Mark Boots
Published: January 30, 2024
Last Updated: February 3, 2024
Downloads: 598
License: MIT
Edit Code online: CodeHim
Read More

This CSS code snippet helps you to create stylish Neumorphic buttons with subtle shadows and icons. Each button is uniquely adorned with a Font Awesome icon, adding a touch of sophistication. The CSS magic behind it ensures responsive design and a delightful hover effect. Perfect for enhancing the visual appeal of your website buttons without compromising on simplicity.

How to Create Neumorphic Buttons With Icons Using CSS

1. First of all, integrate the following HTML structure in the code snippet. Customize the button labels and icons as per your requirements.

<h1>Neumorphic buttons</h1>
<div class="buttons">  
  <button class="neumorphic active">
    <i class="fa-light fa-fire"></i>
    <span>Button 1</span>
  </button>
  <button class="neumorphic">
    <i class="fa-light fa-dna"></i>
    <span>Button 2</span>
  </button>
  <button class="neumorphic">
    <i class="fa-light fa-chart-mixed"></i>
    <span>Button 3</span>
  </button>
  <button class="neumorphic">
    <i class="fa-light fa-atom"></i>
    <span>Button 4</span>
  </button>
  <button class="neumorphic">
    <i class="fa-light fa-seedling"></i>
    <span>Button 5</span>
  </button>
  <button class="neumorphic">
    <i class="fa-light fa-disease"></i>
    <span>Button 6</span>
  </button>
</div>

2. Copy the CSS code into your stylesheet. This CSS is responsible for the neumorphic design, button styles, and hover effects. Ensure you have the necessary dependencies by adding the Font Awesome CSS library. Feel free to tweak the styles to match your project’s color scheme and design preferences. Adjust the font sizes, button dimensions, or shadows as needed.

@import url('https://pro.fontawesome.com/releases/v6.0.0-beta1/css/all.css');

button.neumorphic {
  container-type: inline-size;
  aspect-ratio: 1/1;
  border: 0.5rem solid transparent;
  border-radius: 1rem;
  color: hsl(0 0% 10%);
  background: none;
  
  display: grid;
  place-content: center;
  gap: 1rem;
  
  --shadow: 
    -.5rem -.5rem 1rem hsl(0 0% 100% / .75),
    .5rem .5rem 1rem hsl(0 0% 50% / .5);
  box-shadow: var(--shadow);
  outline: none;  
  transition: all 0.1s;
  
  &:hover, &:focus-visible {
    color: hsl(10 80% 50%);
    scale: 1.1
  }
  &:active, &.active{
    box-shadow:
      var(--shadow),
      inset .5rem .5rem 1rem hsl(0 0% 50% / .5),
      inset -.5rem -.5rem 1rem hsl(0 0% 100% / .75);
    color: hsl(10 80% 50%);
    > i { font-size: 28cqi};
    > span { font-size: 13cqi};
  }

  >i {
    font-size: 31cqi;
  }
  > span {
    font-family: system-ui, sans-serif;
    font-size: 16cqi;
  }
}

.cd__main {
  background-color: #e5e9f4 !important;
  padding: 2rem;
}
h1 {
  text-align: center;
  color: hsl(0 0% 10%);
  font-family: system-ui, sans-serif;
  font-size: 3rem;
  margin-bottom: 30px;
}
.buttons {
  display: grid;
  width: min(75rem, 100%);
  margin-inline: auto;
  grid-template-columns: repeat(auto-fit, minmax(min(8rem, 100%), 1fr));
  gap: 2rem;
}

Experiment with button sizes, spacing, and colors to seamlessly integrate these buttons into your UI. Explore Font Awesome icons and replace the class names in the <i> tags to use different icons.

That’s all! hopefully, you have successfully created neumorphic buttons with icons on your website. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X