# Drum machine pad

> A rubber pad that lights up brighter the closer to the center you hit it, with the velocity shown in the corner.

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

## Where to use it

Inspired by the pads on samplers and drum machines, this square rubber button reads where you strike it: hits near the center glow at full strength, hits on the edge stay dimmer, and a small readout shows the velocity from 0 to 127. The light fades out like an LED under translucent silicone. It fits music apps, beat makers, sound boards and playful dashboards.

The main color is the LED and the secondary color is the hot center of the flash, so magenta with yellow or cyan with white both work. Use the label for the sound name, and build a grid of pads with different labels for a full kit.

## Code

### HTML

```html
<button class="uvq01-pad" type="button"><span class="lt" aria-hidden="true"></span><span class="t">Kick</span><span class="v" aria-hidden="true">VEL <b>000</b></span></button>
```

### CSS

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

.uvq01-pad {
  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;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  width: 7.4em;
  height: 7.4em;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: .8em;
  border-radius: .85em;
  overflow: hidden;
  color: rgba(255,255,255,.85);
  background: radial-gradient(120% 120% at 30% 18%,#56575d,#37383c 58%,#2a2b2f);
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 35%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
  touch-action: manipulation;
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-pad::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.06) .6px,transparent 1px) 0 0/3px 3px;
  pointer-events: none;
}

.uvq01-pad .lt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--hx,50%) var(--hy,50%),var(--c2),var(--c1) 30%,color-mix(in srgb,var(--c1) 55%,transparent) 58%,color-mix(in srgb,var(--c1) 18%,transparent) 90%);
  box-shadow: inset 0 0 0 .1em var(--c1);
  opacity: 0;
  pointer-events: none;
}

.uvq01-pad.is-hit .lt {
  animation: uvq01-pad-hit calc(1.1s / var(--k)) cubic-bezier(.3,.6,.4,1) forwards;
}

.uvq01-pad .t,.uvq01-pad .v {
  position: relative;
}

.uvq01-pad .t {
  font: 700 .74em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.uvq01-pad .v {
  align-self: flex-end;
  font: 600 .62em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .08em;
  opacity: .6;
}

.uvq01-pad .v b {
  font-weight: 800;
}

.uvq01-pad:hover {
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 70%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
}

.uvq01-pad:active,.uvq01-pad.is-down {
  transform: scale(.965);
}

.uvq01-pad:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: calc(.37em + 3px);
}

@keyframes uvq01-pad-hit {
  0%,12% {
    opacity: var(--v,1);
  }
  100% {
    opacity: 0;
  }
}

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

### JavaScript

```js
document.querySelectorAll(".uvq01-pad").forEach(el => {
  const vb=el.querySelector(".v b");
const hit=(v,x,y)=>{el.style.setProperty("--v",v.toFixed(2));el.style.setProperty("--hx",x+"%");el.style.setProperty("--hy",y+"%");vb.textContent=String(Math.round(v*127)).padStart(3,"0");el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit")};
el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect();const x=(e.clientX-r.left)/r.width,y=(e.clientY-r.top)/r.height;const d=Math.min(1,Math.hypot(x-.5,y-.5)/.62);hit(Math.max(.25,1-d*.75),Math.round(x*100),Math.round(y*100))});
el.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){el.classList.add("is-down");hit(.8,50,50)}});
const up=()=>el.classList.remove("is-down");el.addEventListener("keyup",up);el.addEventListener("blur",up)
});
```

### 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-pad {
  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;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  width: 7.4em;
  height: 7.4em;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: .8em;
  border-radius: .85em;
  overflow: hidden;
  color: rgba(255,255,255,.85);
  background: radial-gradient(120% 120% at 30% 18%,#56575d,#37383c 58%,#2a2b2f);
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 35%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
  touch-action: manipulation;
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-pad::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.06) .6px,transparent 1px) 0 0/3px 3px;
  pointer-events: none;
}

.uvq01-pad .lt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--hx,50%) var(--hy,50%),var(--c2),var(--c1) 30%,color-mix(in srgb,var(--c1) 55%,transparent) 58%,color-mix(in srgb,var(--c1) 18%,transparent) 90%);
  box-shadow: inset 0 0 0 .1em var(--c1);
  opacity: 0;
  pointer-events: none;
}

.uvq01-pad.is-hit .lt {
  animation: uvq01-pad-hit calc(1.1s / var(--k)) cubic-bezier(.3,.6,.4,1) forwards;
}

.uvq01-pad .t,.uvq01-pad .v {
  position: relative;
}

.uvq01-pad .t {
  font: 700 .74em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.uvq01-pad .v {
  align-self: flex-end;
  font: 600 .62em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .08em;
  opacity: .6;
}

.uvq01-pad .v b {
  font-weight: 800;
}

.uvq01-pad:hover {
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 70%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
}

.uvq01-pad:active,.uvq01-pad.is-down {
  transform: scale(.965);
}

.uvq01-pad:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: calc(.37em + 3px);
}

@keyframes uvq01-pad-hit {
  0%,12% {
    opacity: var(--v,1);
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-pad,.uvq01-pad *,.uvq01-pad *::before,.uvq01-pad *::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 vb=el.querySelector(".v b");
const hit=(v,x,y)=>{el.style.setProperty("--v",v.toFixed(2));el.style.setProperty("--hx",x+"%");el.style.setProperty("--hy",y+"%");vb.textContent=String(Math.round(v*127)).padStart(3,"0");el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit")};
el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect();const x=(e.clientX-r.left)/r.width,y=(e.clientY-r.top)/r.height;const d=Math.min(1,Math.hypot(x-.5,y-.5)/.62);hit(Math.max(.25,1-d*.75),Math.round(x*100),Math.round(y*100))});
el.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){el.classList.add("is-down");hit(.8,50,50)}});
const up=()=>el.classList.remove("is-down");el.addEventListener("keyup",up);el.addEventListener("blur",up)
}

export default function BtnDrumPad() {
  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": "#ff2f6d",
          "--c2": "#ffd36e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <button className="uvq01-pad" type="button"><span className="lt" aria-hidden="true"></span><span className="t">Kick</span><span className="v" aria-hidden="true">VEL <b>000</b></span></button>
      </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 “Drum machine pad” block (Buttons) from AIMRAN Library to my project.

## What it is
A rubber pad that lights up brighter the closer to the center you hit it, with the velocity shown in the corner.

## Chosen settings
- Main color: #ff2f6d
- Secondary color: #ffd36e
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Bombo"

## 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-pad {
  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;
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  user-select: none;
  width: 7.4em;
  height: 7.4em;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: .8em;
  border-radius: .85em;
  overflow: hidden;
  color: rgba(255,255,255,.85);
  background: radial-gradient(120% 120% at 30% 18%,#56575d,#37383c 58%,#2a2b2f);
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 35%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
  touch-action: manipulation;
  transition: transform calc(0.08s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-pad::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 1px 1px,rgba(255,255,255,.06) .6px,transparent 1px) 0 0/3px 3px;
  pointer-events: none;
}

.uvq01-pad .lt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--hx,50%) var(--hy,50%),var(--c2),var(--c1) 30%,color-mix(in srgb,var(--c1) 55%,transparent) 58%,color-mix(in srgb,var(--c1) 18%,transparent) 90%);
  box-shadow: inset 0 0 0 .1em var(--c1);
  opacity: 0;
  pointer-events: none;
}

.uvq01-pad.is-hit .lt {
  animation: uvq01-pad-hit calc(1.1s / var(--k)) cubic-bezier(.3,.6,.4,1) forwards;
}

.uvq01-pad .t,.uvq01-pad .v {
  position: relative;
}

.uvq01-pad .t {
  font: 700 .74em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.uvq01-pad .v {
  align-self: flex-end;
  font: 600 .62em/1 ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
  letter-spacing: .08em;
  opacity: .6;
}

.uvq01-pad .v b {
  font-weight: 800;
}

.uvq01-pad:hover {
  box-shadow: inset 0 .12em .2em rgba(255,255,255,.16),inset 0 -.25em .5em rgba(0,0,0,.45),inset 0 0 0 .08em color-mix(in srgb,var(--c1) 70%,transparent),0 0 0 .32em #151517,0 0 0 .37em #2c2c30,0 16px 26px -12px rgba(0,0,0,.7);
}

.uvq01-pad:active,.uvq01-pad.is-down {
  transform: scale(.965);
}

.uvq01-pad:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: calc(.37em + 3px);
}

@keyframes uvq01-pad-hit {
  0%,12% {
    opacity: var(--v,1);
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-pad,.uvq01-pad *,.uvq01-pad *::before,.uvq01-pad *::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 vb=el.querySelector(".v b");
const hit=(v,x,y)=>{el.style.setProperty("--v",v.toFixed(2));el.style.setProperty("--hx",x+"%");el.style.setProperty("--hy",y+"%");vb.textContent=String(Math.round(v*127)).padStart(3,"0");el.classList.remove("is-hit");void el.offsetWidth;el.classList.add("is-hit")};
el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect();const x=(e.clientX-r.left)/r.width,y=(e.clientY-r.top)/r.height;const d=Math.min(1,Math.hypot(x-.5,y-.5)/.62);hit(Math.max(.25,1-d*.75),Math.round(x*100),Math.round(y*100))});
el.addEventListener("keydown",e=>{if((e.key==="Enter"||e.key===" ")&&!e.repeat){el.classList.add("is-down");hit(.8,50,50)}});
const up=()=>el.classList.remove("is-down");el.addEventListener("keyup",up);el.addEventListener("blur",up)
}

export default function BtnDrumPad() {
  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": "#ff2f6d",
          "--c2": "#ffd36e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <button className="uvq01-pad" type="button"><span className="lt" aria-hidden="true"></span><span className="t">Kick</span><span className="v" aria-hidden="true">VEL <b>000</b></span></button>
      </div>
    </>
  );
}
```

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