About this snippet

Give your buttons a highly satisfying physical feel. We crafted precise 3D box shadows and translated depth layers, so the button clicks exactly like a real mechanical keyboard switch.

Size
2.1 KB
Uses
HTML, CSS
Loads
Nothing external
Views
170
<div class="keyboard-board">
  <button class="mech-key">
    <div class="key-cap">
      <span class="key-legend">ENTER</span>
    </div>
    <div class="key-base"></div>
  </button>
</div>
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  margin: 0;
  background: #18181b;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.keyboard-board {
  background: #27272a;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.8), inset 0 2px 2px rgba(255,255,255,0.05);
  border: 1px solid #111827;
}

.mech-key {
  position: relative;
  background: transparent;
  border: none;
  padding: 0;
  width: 140px;
  height: 100px;
  cursor: pointer;
  outline: none;
}

.key-base {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 90px;
  background: #09090b;
  border-radius: 12px;
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.8);
  z-index: 1;
}

.key-cap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 90px;
  background: linear-gradient(180deg, #52525b, #3f3f46);
  border-radius: 12px;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  /* Top highlighting and profound bottom shadow for depth */
  box-shadow: inset 0 2px 2px rgba(255,255,255,0.2), inset 0 -6px 10px rgba(0,0,0,0.6), 0 10px 0 #18181b, 0 10px 10px rgba(0,0,0,0.5);
  transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #71717a;
  border-bottom: none;
}

.key-legend {
  color: #e4e4e7;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* The satisfying press interaction */
.mech-key:active .key-cap {
  transform: translateY(8px);
  /* Compress the shadow to mimic physical travel distance */
  box-shadow: inset 0 2px 2px rgba(255,255,255,0.2), inset 0 -2px 6px rgba(0,0,0,0.6), 0 2px 0 #18181b, 0 2px 5px rgba(0,0,0,0.5);
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save