{ CF }

30 CSS Badges

Keycap Shortcut

A key is a physical object. Three stacked box-shadows form the edge — bottom face, outer drop, top highlight. Click any key and feel it go down. Cmd-K and friends, the way they were meant to look.

CSS + JS MIT licensed

Keycap Shortcut the 4th of 30 designs in the 30 CSS Badges collection. The design pairs CSS styling with a small amount of JavaScript for interactivity. Copy the HTML, CSS and JavaScript panels below into your project — the JS is self-contained, has zero dependencies, and is safe to drop into any framework (React, Vue, Svelte, plain HTML). The design honours prefers-reduced-motion and uses real semantic markup, so it ships accessibility-ready out of the box.

Live preview

Open in playground

The code

<div class="key-stage">
  <div class="key-combo-row">
    <div class="key-combo">
      <div class="key-cap key-wide">⌘</div>
      <div class="key-sep">+</div>
      <div class="key-cap">K</div>
    </div>
    <div class="key-combo-label">Command Palette</div>
  </div>

  <div class="key-combo-row">
    <div class="key-combo">
      <div class="key-cap key-wide">⌘</div>
      <div class="key-sep">+</div>
      <div class="key-cap key-wide">⇧</div>
      <div class="key-sep">+</div>
      <div class="key-cap">P</div>
    </div>
    <div class="key-combo-label">Quick Actions</div>
  </div>

  <div class="key-combo-row">
    <div class="key-combo">
      <div class="key-cap key-wide">⌥</div>
      <div class="key-sep">+</div>
      <div class="key-cap key-xl">⌫</div>
    </div>
    <div class="key-combo-label">Delete Word</div>
  </div>
</div>
.key-stage {
  background: #edecea;
  padding: 60px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: center;
  align-items: center;
  min-height: 380px;
}
.key-combo {
  display: flex;
  align-items: center;
  gap: 6px;
}
.key-sep {
  font-family: system-ui, "Bricolage Grotesque", sans-serif;
  font-size: 14px;
  color: #888;
  padding: 0 2px;
}
.key-cap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  background: linear-gradient(180deg, #f8f8f6 0%, #e8e8e3 100%);
  border: 1px solid #bbb;
  border-radius: 6px;
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  letter-spacing: 0;
  cursor: pointer;
  user-select: none;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.9) inset,
    0 -1px 0 rgba(0,0,0,0.08) inset,
    0 3px 0 #999,
    0 4px 4px rgba(0,0,0,0.18);
  transition: transform 0.06s, box-shadow 0.06s;
  position: relative;
}
.key-cap::before {
  content: '';
  position: absolute;
  inset: 2px 2px 6px;
  border-radius: 4px;
  border-top: 1px solid rgba(255,255,255,0.6);
  pointer-events: none;
}
.key-cap:active,
.key-cap.is-pressed {
  transform: translateY(2px);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.9) inset,
    0 -1px 0 rgba(0,0,0,0.08) inset,
    0 1px 0 #999,
    0 2px 2px rgba(0,0,0,0.18);
}
.key-wide { min-width: 72px; font-size: 13px; }
.key-xl   { min-width: 96px; font-size: 13px; }
.key-combo-label {
  font-family: system-ui, "Bricolage Grotesque", sans-serif;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #888;
  text-align: center;
  margin-top: 6px;
}
.key-combo-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
// Click any key to depress it briefly. Matches the CSS :active state
// but lets the visual hold for 200ms so the press registers visually
// even on a quick tap.
document.querySelectorAll('.key-cap').forEach(function (k) {
  k.addEventListener('click', function () {
    k.classList.add('is-pressed');
    setTimeout(function () { k.classList.remove('is-pressed'); }, 200);
  });
});

Search CodeFronts

Loading…