# Mechanical keycap button

> A sculpted keycap on a keyboard plate that travels down for real and sends a ring of light across the plate.

- Category: [Buttons](https://library.aimran.es/components/buttons)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-btn-keycap
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Mechanical keyboards have a loyal fan base, and this button borrows their look: a sculpted keycap with a concave top and legend, sitting on an anodized plate with colored underglow. Each press drops the cap with real key travel and fires a reactive light ripple, also when you use Enter or Space. It suits developer tools, keyboard shortcut hints and gaming sites.

Use the main color for the keycap, like a classic orange Escape key, and the secondary color for the RGB glow. Short labels such as Send, Run or Enter look most natural, and a few of these together make a convincing shortcut legend.

## Code

### HTML

```html
<div class="uvq01-key"><span class="rp" aria-hidden="true"></span><button class="k" type="button"><span class="cap"><span class="t">Send</span><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 5v7a3 3 0 0 1-3 3H6"/><path d="M10 11l-4 4 4 4"/></svg></span></button></div>
```

### CSS

```css
.uvq01-key {
  --c1: #ef6a3a;
  --c2: #5ce1ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq01-key {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  place-items: center;
  padding: 1.3em 1.7em 1.7em;
  border-radius: 1.1em;
  overflow: hidden;
  background: radial-gradient(circle at 50% 60%,color-mix(in srgb,var(--c2) 14%,transparent),transparent 60%),linear-gradient(180deg,#27282d,#1a1b1f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09),inset 0 0 0 1px rgba(0,0,0,.6),0 16px 30px -18px rgba(0,0,0,.7);
}

.uvq01-key::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.05) .6px,transparent 1px) 0 0/4px 4px;
  pointer-events: none;
}

.uvq01-key .rp {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7em;
  height: 7em;
  margin: -3.5em;
  border-radius: 50%;
  box-shadow: 0 0 0 .22em var(--c2),0 0 1.4em .3em var(--c2),inset 0 0 1.2em .2em color-mix(in srgb,var(--c2) 60%,transparent);
  opacity: 0;
  pointer-events: none;
}

.uvq01-key.is-hit .rp {
  animation: uvq01-key-rp calc(0.75s / var(--k)) cubic-bezier(.2,.7,.3,1);
}

.uvq01-key .k {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
  display: block;
  width: 8.4em;
  height: 4.3em;
  border-radius: .75em;
  background: linear-gradient(180deg,color-mix(in srgb,var(--c1) 80%,#000),color-mix(in srgb,var(--c1) 62%,#000));
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 1.6em -.3em var(--c2);
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-key .cap {
  position: absolute;
  inset: .26em .5em .72em;
  display: grid;
  grid-template: 1fr auto/1fr auto;
  padding: .6em .7em .55em;
  border-radius: .55em;
  text-align: left;
  font-weight: 750;
  font-size: .95em;
  color: color-mix(in srgb,var(--c1) 22%,#1a1410);
  background: radial-gradient(130% 100% at 50% -10%,color-mix(in srgb,var(--c1) 70%,#fff),var(--c1) 62%);
  box-shadow: inset 0 .1em .12em rgba(255,255,255,.45),inset 0 -.18em .35em color-mix(in srgb,var(--c1) 70%,#000);
}

.uvq01-key .t {
  grid-area: 1/1;
}

.uvq01-key svg {
  grid-area: 2/2;
  width: 1.15em;
  height: 1.15em;
  opacity: .85;
}

.uvq01-key .k:hover {
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 2.2em 0 var(--c2);
}

.uvq01-key .k:active,.uvq01-key .k.is-down {
  transform: translateY(.27em);
  box-shadow: 0 .05em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .1em .3em rgba(0,0,0,.6),0 .2em 2.6em .3em var(--c2);
}

.uvq01-key .k:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@keyframes uvq01-key-rp {
  0% {
    opacity: .9;
    transform: scale(.55);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-key,.uvq01-key *,.uvq01-key *::before,.uvq01-key *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq01-key").forEach(el => {
  const k=el.querySelector(".k");let tm=0;
const hit=()=>{el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit");clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-hit"),1000)};
k.addEventListener("pointerdown",hit);
k.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){k.classList.add("is-down");hit()}});
const up=()=>k.classList.remove("is-down");k.addEventListener("keyup",up);k.addEventListener("blur",up);
return()=>clearTimeout(tm)
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq01-key {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  place-items: center;
  padding: 1.3em 1.7em 1.7em;
  border-radius: 1.1em;
  overflow: hidden;
  background: radial-gradient(circle at 50% 60%,color-mix(in srgb,var(--c2) 14%,transparent),transparent 60%),linear-gradient(180deg,#27282d,#1a1b1f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09),inset 0 0 0 1px rgba(0,0,0,.6),0 16px 30px -18px rgba(0,0,0,.7);
}

.uvq01-key::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.05) .6px,transparent 1px) 0 0/4px 4px;
  pointer-events: none;
}

.uvq01-key .rp {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7em;
  height: 7em;
  margin: -3.5em;
  border-radius: 50%;
  box-shadow: 0 0 0 .22em var(--c2),0 0 1.4em .3em var(--c2),inset 0 0 1.2em .2em color-mix(in srgb,var(--c2) 60%,transparent);
  opacity: 0;
  pointer-events: none;
}

.uvq01-key.is-hit .rp {
  animation: uvq01-key-rp calc(0.75s / var(--k)) cubic-bezier(.2,.7,.3,1);
}

.uvq01-key .k {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
  display: block;
  width: 8.4em;
  height: 4.3em;
  border-radius: .75em;
  background: linear-gradient(180deg,color-mix(in srgb,var(--c1) 80%,#000),color-mix(in srgb,var(--c1) 62%,#000));
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 1.6em -.3em var(--c2);
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-key .cap {
  position: absolute;
  inset: .26em .5em .72em;
  display: grid;
  grid-template: 1fr auto/1fr auto;
  padding: .6em .7em .55em;
  border-radius: .55em;
  text-align: left;
  font-weight: 750;
  font-size: .95em;
  color: color-mix(in srgb,var(--c1) 22%,#1a1410);
  background: radial-gradient(130% 100% at 50% -10%,color-mix(in srgb,var(--c1) 70%,#fff),var(--c1) 62%);
  box-shadow: inset 0 .1em .12em rgba(255,255,255,.45),inset 0 -.18em .35em color-mix(in srgb,var(--c1) 70%,#000);
}

.uvq01-key .t {
  grid-area: 1/1;
}

.uvq01-key svg {
  grid-area: 2/2;
  width: 1.15em;
  height: 1.15em;
  opacity: .85;
}

.uvq01-key .k:hover {
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 2.2em 0 var(--c2);
}

.uvq01-key .k:active,.uvq01-key .k.is-down {
  transform: translateY(.27em);
  box-shadow: 0 .05em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .1em .3em rgba(0,0,0,.6),0 .2em 2.6em .3em var(--c2);
}

.uvq01-key .k:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@keyframes uvq01-key-rp {
  0% {
    opacity: .9;
    transform: scale(.55);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-key,.uvq01-key *,.uvq01-key *::before,.uvq01-key *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=el.querySelector(".k");let tm=0;
const hit=()=>{el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit");clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-hit"),1000)};
k.addEventListener("pointerdown",hit);
k.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){k.classList.add("is-down");hit()}});
const up=()=>k.classList.remove("is-down");k.addEventListener("keyup",up);k.addEventListener("blur",up);
return()=>clearTimeout(tm)
}

export default function BtnKeycap() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ef6a3a",
          "--c2": "#5ce1ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq01-key"><span className="rp" aria-hidden="true"></span><button className="k" type="button"><span className="cap"><span className="t">Send</span><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M19 5v7a3 3 0 0 1-3 3H6" /><path d="M10 11l-4 4 4 4" /></svg></span></button></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Mechanical keycap button” block (Buttons) from AIMRAN Library to my project.

## What it is
A sculpted keycap on a keyboard plate that travels down for real and sends a ring of light across the plate.

## Chosen settings
- Main color: #ef6a3a
- Secondary color: #5ce1ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Send"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq01-key {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-grid;
  place-items: center;
  padding: 1.3em 1.7em 1.7em;
  border-radius: 1.1em;
  overflow: hidden;
  background: radial-gradient(circle at 50% 60%,color-mix(in srgb,var(--c2) 14%,transparent),transparent 60%),linear-gradient(180deg,#27282d,#1a1b1f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09),inset 0 0 0 1px rgba(0,0,0,.6),0 16px 30px -18px rgba(0,0,0,.7);
}

.uvq01-key::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.05) .6px,transparent 1px) 0 0/4px 4px;
  pointer-events: none;
}

.uvq01-key .rp {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7em;
  height: 7em;
  margin: -3.5em;
  border-radius: 50%;
  box-shadow: 0 0 0 .22em var(--c2),0 0 1.4em .3em var(--c2),inset 0 0 1.2em .2em color-mix(in srgb,var(--c2) 60%,transparent);
  opacity: 0;
  pointer-events: none;
}

.uvq01-key.is-hit .rp {
  animation: uvq01-key-rp calc(0.75s / var(--k)) cubic-bezier(.2,.7,.3,1);
}

.uvq01-key .k {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
  display: block;
  width: 8.4em;
  height: 4.3em;
  border-radius: .75em;
  background: linear-gradient(180deg,color-mix(in srgb,var(--c1) 80%,#000),color-mix(in srgb,var(--c1) 62%,#000));
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 1.6em -.3em var(--c2);
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-key .cap {
  position: absolute;
  inset: .26em .5em .72em;
  display: grid;
  grid-template: 1fr auto/1fr auto;
  padding: .6em .7em .55em;
  border-radius: .55em;
  text-align: left;
  font-weight: 750;
  font-size: .95em;
  color: color-mix(in srgb,var(--c1) 22%,#1a1410);
  background: radial-gradient(130% 100% at 50% -10%,color-mix(in srgb,var(--c1) 70%,#fff),var(--c1) 62%);
  box-shadow: inset 0 .1em .12em rgba(255,255,255,.45),inset 0 -.18em .35em color-mix(in srgb,var(--c1) 70%,#000);
}

.uvq01-key .t {
  grid-area: 1/1;
}

.uvq01-key svg {
  grid-area: 2/2;
  width: 1.15em;
  height: 1.15em;
  opacity: .85;
}

.uvq01-key .k:hover {
  box-shadow: 0 .32em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .5em .9em -.1em rgba(0,0,0,.6),0 .45em 2.2em 0 var(--c2);
}

.uvq01-key .k:active,.uvq01-key .k.is-down {
  transform: translateY(.27em);
  box-shadow: 0 .05em 0 color-mix(in srgb,var(--c1) 42%,#000),0 .1em .3em rgba(0,0,0,.6),0 .2em 2.6em .3em var(--c2);
}

.uvq01-key .k:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@keyframes uvq01-key-rp {
  0% {
    opacity: .9;
    transform: scale(.55);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-key,.uvq01-key *,.uvq01-key *::before,.uvq01-key *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=el.querySelector(".k");let tm=0;
const hit=()=>{el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit");clearTimeout(tm);tm=setTimeout(()=>el.classList.remove("is-hit"),1000)};
k.addEventListener("pointerdown",hit);
k.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){k.classList.add("is-down");hit()}});
const up=()=>k.classList.remove("is-down");k.addEventListener("keyup",up);k.addEventListener("blur",up);
return()=>clearTimeout(tm)
}

export default function BtnKeycap() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ef6a3a",
          "--c2": "#5ce1ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq01-key"><span className="rp" aria-hidden="true"></span><button className="k" type="button"><span className="cap"><span className="t">Send</span><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M19 5v7a3 3 0 0 1-3 3H6" /><path d="M10 11l-4 4 4 4" /></svg></span></button></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
