AI CSS Animations

Neumorphism Button

A soft UI button that sits raised on its own surface and sinks into it on hover. Two box-shadows swap from outset to inset, listed in both states so they interpolate.

Also known as: neumorphic button css, soft ui button, inset shadow button.

HTML

<div class="btn-neumorphic">
  <button class="btn-neumorphic-btn">
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M8 5.5v13l10.5-6.5z"/></svg>
    Play
  </button>
</div>

CSS

.btn-neumorphic {
  --c: var(--btn-color, #3b82f6);
  --surface: color-mix(in srgb, var(--c) 6%, #e3e7ee);
  --low: color-mix(in srgb, var(--c) 14%, #a4aec0);
  font-size: var(--btn-size, 18px);
  display: inline-grid;
  place-items: center;
  padding: 1.8em 3em;
  border-radius: 1.25em;
  background: var(--surface);
}
.btn-neumorphic-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.85em 1.8em;
  border: 0;
  border-radius: 0.9em;
  background: var(--surface);
  color: color-mix(in srgb, var(--c) 35%, #5b6475);
  font: 600 1em/1.2 system-ui, sans-serif;
  cursor: pointer;
  box-shadow:
    0.4em 0.4em 0.8em var(--low),
    -0.4em -0.4em 0.8em #fff,
    inset 0 0 0 transparent,
    inset 0 0 0 transparent;
  transition: box-shadow 0.3s ease, color 0.3s ease;
}
.btn-neumorphic-btn svg {
  width: 1em;
  height: 1em;
  transition: transform 0.3s ease;
}
.btn-neumorphic-btn:is(:hover, :focus-visible) {
  color: var(--c);
  box-shadow:
    0 0 0 transparent,
    0 0 0 transparent,
    inset 0.25em 0.25em 0.5em var(--low),
    inset -0.25em -0.25em 0.5em #fff;
}
.btn-neumorphic-btn:is(:hover, :focus-visible) svg { transform: scale(0.9); }

@media (prefers-reduced-motion: reduce) {
  .btn-neumorphic, .btn-neumorphic *, .btn-neumorphic::before, .btn-neumorphic::after, .btn-neumorphic *::before, .btn-neumorphic *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --btn-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --btn-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar buttons