30 CSS Badges04 / 30

CSS + JSMIT licensed

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.

Published

Live Demo
Try it

The code

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

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

  <div class="bdg-04-combo-row">
    <div class="bdg-04-combo">
      <div class="bdg-04-cap bdg-04-wide">⌥</div>
      <div class="bdg-04-sep">+</div>
      <div class="bdg-04-cap bdg-04-xl">⌫</div>
    </div>
    <div class="bdg-04-combo-label">Delete Word</div>
  </div>
</div>
.bdg-04-stage {
  background: #edecea;
  padding: 60px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 100vh;
}

.bdg-04-combo {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bdg-04-sep {
  font-family: system-ui, "Bricolage Grotesque", sans-serif;
  font-size: 14px;
  color: #888;
  padding: 0 2px;
}

.bdg-04-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;
}

.bdg-04-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;
}

.bdg-04-cap:active,
.bdg-04-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);
}

.bdg-04-wide {
  min-width: 72px;
  font-size: 13px;
}

.bdg-04-xl {
  min-width: 96px;
  font-size: 13px;
}

.bdg-04-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;
}

.bdg-04-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('.bdg-04-cap').forEach(function (k) {
  k.addEventListener('click', function () {
    k.classList.add('is-pressed');
    setTimeout(function () { k.classList.remove('is-pressed'); }, 200);
  });
});
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Badge from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Keycap Shortcut
Source: https://codefronts.com/snippets/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.
## HTML
```html
<div class="bdg-04-stage">
  <div class="bdg-04-combo-row">
    <div class="bdg-04-combo">
      <div class="bdg-04-cap bdg-04-wide">⌘</div>
      <div class="bdg-04-sep">+</div>
      <div class="bdg-04-cap">K</div>
    </div>
    <div class="bdg-04-combo-label">Command Palette</div>
  </div>

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

  <div class="bdg-04-combo-row">
    <div class="bdg-04-combo">
      <div class="bdg-04-cap bdg-04-wide">⌥</div>
      <div class="bdg-04-sep">+</div>
      <div class="bdg-04-cap bdg-04-xl">⌫</div>
    </div>
    <div class="bdg-04-combo-label">Delete Word</div>
  </div>
</div>
```
## CSS
```css
.bdg-04-stage {
  background: #edecea;
  padding: 60px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 100vh;
}

.bdg-04-combo {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bdg-04-sep {
  font-family: system-ui, "Bricolage Grotesque", sans-serif;
  font-size: 14px;
  color: #888;
  padding: 0 2px;
}

.bdg-04-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;
}

.bdg-04-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;
}

.bdg-04-cap:active,
.bdg-04-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);
}

.bdg-04-wide {
  min-width: 72px;
  font-size: 13px;
}

.bdg-04-xl {
  min-width: 96px;
  font-size: 13px;
}

.bdg-04-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;
}

.bdg-04-combo-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
```

## JavaScript
```js
// 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('.bdg-04-cap').forEach(function (k) {
  k.addEventListener('click', function () {
    k.classList.add('is-pressed');
    setTimeout(function () { k.classList.remove('is-pressed'); }, 200);
  });
});
```

How this works

A keyboard-cap-shaped badge: rectangular with rounded corners, a hairline top edge highlight, a deep bottom edge shadow for physical depth, and the shortcut key rendered in mono type inside. Press interaction: on :active (or JS-driven click), the cap depresses via transform:translateY(1px) and the shadow collapses — physical feedback.

The JS layer adds a global keydown listener so pressing the actual keyboard key visually depresses the cap on-screen — the pattern GitHub, Notion, Linear, Superhuman, and every command-palette-driven app uses to teach shortcuts.

Make it yours

  • Rebrand the cap face from --cap-bg, --cap-edge, and --cap-shadow on the wrapper.
  • Change the key text — the cap sizes to fit (display:inline-flex with padding).
  • Swap the mono font for a display font for a retro-terminal look.
  • Add a modifier chain by nesting multiple caps with a &ldquo;+&rdquo; between them (⌘ + K).
  • Change the press depth via the translateY value in the :active state — 1px subtle, 3px pronounced.

Gotchas — read before shipping

  • Use real <kbd> element semantics — screen readers announce it as a keyboard shortcut, and it defaults to a monospace stack.
  • The visual press must fire on both :active AND JS-triggered class toggle — otherwise real keydowns don't animate the cap.
  • The global keydown listener should check event.target to avoid triggering while the user is typing in an input field.
  • Provide aria-label if the visible key uses a symbol (⌘) that screen readers might not announce correctly — e.g. aria-label="Command K".

Browser support

ChromeSafariFirefoxEdge
43+9+16+43+

CSS transforms, transitions, and <kbd> semantics are universally supported. The keydown event is standard.

Techniques used in this demo

Search CodeFronts

Loading…