# Press-and-hold delete button

> Keep it pressed to confirm: the button fills with red, the bin lid trembles and the action only fires once the bar is full.

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

## Where to use it

Destructive actions deserve a little friction, and this button asks for it physically: the user has to hold it down while a red bar crosses from left to right and the lid of the bin icon starts to rattle. Releasing early drains the bar back. It works with mouse, touch and the keyboard, which makes it a good fit for deleting accounts, files or projects.

Set how long the press must last with the hold time slider; around one and a half seconds feels deliberate without being annoying. Keep the main color red or orange so the risk reads at a glance, and place a normal cancel button next to it.

## Code

### HTML

```html
<button class="uvq01-hld" type="button"><span class="f" aria-hidden="true"></span><span class="ic" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g class="lid"><path d="M4 7h16"/><path d="M9.5 7V4.5h5V7"/></g><path d="M6 7l1 13h10l1-13"/><path d="M10 11v5M14 11v5"/></svg></span><span class="w"><span class="t">Hold to delete</span><span class="d">Deleted</span></span></button>
```

### CSS

```css
.uvq01-hld {
  --c1: #e5383b;
  --c2: #232227;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --hold: 1.4;
  /* tiempo de pulsación */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq01-hld {
  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;
  padding: 1.05em 1.8em 1.05em 1.5em;
  border-radius: .9em;
  overflow: hidden;
  color: #fff;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.6);
  touch-action: none;
  -webkit-touch-callout: none;
  --p: 0;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-hld .f {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1));
  transform-origin: 0 50%;
  transform: scaleX(var(--p));
}

.uvq01-hld:hover .f {
  transform: scaleX(max(var(--p),.035));
}

.uvq01-hld .ic {
  position: relative;
  display: grid;
  width: 1.25em;
  height: 1.25em;
}

.uvq01-hld svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.uvq01-hld .lid {
  transform-origin: 20px 7px;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-hld .w {
  position: relative;
  display: grid;
}

.uvq01-hld .t,.uvq01-hld .d {
  grid-area: 1/1;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),visibility calc(0.25s / var(--k));
}

.uvq01-hld .d {
  opacity: 0;
  visibility: hidden;
  translate: 0 .7em;
}

.uvq01-hld.is-hold {
  transform: scale(.975);
}

.uvq01-hld.is-hold .lid {
  animation: uvq01-hld-lid calc(0.16s / var(--k)) linear infinite;
}

.uvq01-hld.is-done {
  background: var(--c1);
}

.uvq01-hld.is-done .t {
  opacity: 0;
  visibility: hidden;
  translate: 0 -.7em;
}

.uvq01-hld.is-done .d {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
}

.uvq01-hld.is-done .lid {
  transform: rotate(-38deg) translate(-2px,-3px);
}

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

@keyframes uvq01-hld-lid {
  0%,100% {
    transform: rotate(-8deg) translateY(-1px);
  }
  50% {
    transform: rotate(-16deg) translateY(-2.5px);
  }
}

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

### JavaScript

```js
document.querySelectorAll(".uvq01-hld").forEach(el => {
  let p=0,on=false,done=false,raf=0,last=0,tm=0;
const dur=()=>(parseFloat(getComputedStyle(el).getPropertyValue("--hold"))||1.4)*1000;
const tick=t=>{const dt=last?Math.min(64,t-last):16;last=t;p=Math.max(0,Math.min(1,on?p+dt/dur():p-dt/320));el.style.setProperty("--p",p.toFixed(3));
if(on&&p>=1){on=false;done=true;raf=0;last=0;el.classList.remove("is-hold");el.classList.add("is-done");tm=setTimeout(()=>{done=false;el.classList.remove("is-done");raf=requestAnimationFrame(tick)},1800);return}
if(on||p>0)raf=requestAnimationFrame(tick);else{raf=0;last=0}};
const run=()=>{if(!raf){last=0;raf=requestAnimationFrame(tick)}};
const start=()=>{if(done||on)return;on=true;el.classList.add("is-hold");run()};
const stop=()=>{if(!on)return;on=false;el.classList.remove("is-hold");run()};
el.addEventListener("pointerdown",e=>{if(e.button)return;try{el.setPointerCapture(e.pointerId)}catch(_){}start()});
el.addEventListener("pointerup",stop);el.addEventListener("pointercancel",stop);el.addEventListener("lostpointercapture",stop);
el.addEventListener("keydown",e=>{if(e.key===" "||e.key==="Enter"){e.preventDefault();if(!e.repeat)start()}});
el.addEventListener("keyup",e=>{if(e.key===" "||e.key==="Enter")stop()});
el.addEventListener("blur",stop);el.addEventListener("contextmenu",e=>e.preventDefault());
return()=>{cancelAnimationFrame(raf);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-hld {
  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;
  padding: 1.05em 1.8em 1.05em 1.5em;
  border-radius: .9em;
  overflow: hidden;
  color: #fff;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.6);
  touch-action: none;
  -webkit-touch-callout: none;
  --p: 0;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-hld .f {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1));
  transform-origin: 0 50%;
  transform: scaleX(var(--p));
}

.uvq01-hld:hover .f {
  transform: scaleX(max(var(--p),.035));
}

.uvq01-hld .ic {
  position: relative;
  display: grid;
  width: 1.25em;
  height: 1.25em;
}

.uvq01-hld svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.uvq01-hld .lid {
  transform-origin: 20px 7px;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-hld .w {
  position: relative;
  display: grid;
}

.uvq01-hld .t,.uvq01-hld .d {
  grid-area: 1/1;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),visibility calc(0.25s / var(--k));
}

.uvq01-hld .d {
  opacity: 0;
  visibility: hidden;
  translate: 0 .7em;
}

.uvq01-hld.is-hold {
  transform: scale(.975);
}

.uvq01-hld.is-hold .lid {
  animation: uvq01-hld-lid calc(0.16s / var(--k)) linear infinite;
}

.uvq01-hld.is-done {
  background: var(--c1);
}

.uvq01-hld.is-done .t {
  opacity: 0;
  visibility: hidden;
  translate: 0 -.7em;
}

.uvq01-hld.is-done .d {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
}

.uvq01-hld.is-done .lid {
  transform: rotate(-38deg) translate(-2px,-3px);
}

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

@keyframes uvq01-hld-lid {
  0%,100% {
    transform: rotate(-8deg) translateY(-1px);
  }
  50% {
    transform: rotate(-16deg) translateY(-2.5px);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-hld,.uvq01-hld *,.uvq01-hld *::before,.uvq01-hld *::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) {
  let p=0,on=false,done=false,raf=0,last=0,tm=0;
const dur=()=>(parseFloat(getComputedStyle(el).getPropertyValue("--hold"))||1.4)*1000;
const tick=t=>{const dt=last?Math.min(64,t-last):16;last=t;p=Math.max(0,Math.min(1,on?p+dt/dur():p-dt/320));el.style.setProperty("--p",p.toFixed(3));
if(on&&p>=1){on=false;done=true;raf=0;last=0;el.classList.remove("is-hold");el.classList.add("is-done");tm=setTimeout(()=>{done=false;el.classList.remove("is-done");raf=requestAnimationFrame(tick)},1800);return}
if(on||p>0)raf=requestAnimationFrame(tick);else{raf=0;last=0}};
const run=()=>{if(!raf){last=0;raf=requestAnimationFrame(tick)}};
const start=()=>{if(done||on)return;on=true;el.classList.add("is-hold");run()};
const stop=()=>{if(!on)return;on=false;el.classList.remove("is-hold");run()};
el.addEventListener("pointerdown",e=>{if(e.button)return;try{el.setPointerCapture(e.pointerId)}catch(_){}start()});
el.addEventListener("pointerup",stop);el.addEventListener("pointercancel",stop);el.addEventListener("lostpointercapture",stop);
el.addEventListener("keydown",e=>{if(e.key===" "||e.key==="Enter"){e.preventDefault();if(!e.repeat)start()}});
el.addEventListener("keyup",e=>{if(e.key===" "||e.key==="Enter")stop()});
el.addEventListener("blur",stop);el.addEventListener("contextmenu",e=>e.preventDefault());
return()=>{cancelAnimationFrame(raf);clearTimeout(tm)}
}

export default function BtnHoldDelete() {
  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": "#e5383b",
          "--c2": "#232227",
          "--s": "16px",
          "--k": "1",
          "--hold": "1.4",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <button className="uvq01-hld" type="button"><span className="f" aria-hidden="true"></span><span className="ic" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><g className="lid"><path d="M4 7h16" /><path d="M9.5 7V4.5h5V7" /></g><path d="M6 7l1 13h10l1-13" /><path d="M10 11v5M14 11v5" /></svg></span><span className="w"><span className="t">Hold to delete</span><span className="d">Deleted</span></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 “Press-and-hold delete button” block (Buttons) from AIMRAN Library to my project.

## What it is
Keep it pressed to confirm: the button fills with red, the bin lid trembles and the action only fires once the bar is full.

## Chosen settings
- Main color: #e5383b
- Secondary color: #232227
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Hold time: 1.4s (from 0.6 to 3s)
- Text: "Mantén para borrar"

## 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-hld {
  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;
  padding: 1.05em 1.8em 1.05em 1.5em;
  border-radius: .9em;
  overflow: hidden;
  color: #fff;
  background: var(--c2);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09),0 12px 26px -14px rgba(0,0,0,.6);
  touch-action: none;
  -webkit-touch-callout: none;
  --p: 0;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq01-hld .f {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1));
  transform-origin: 0 50%;
  transform: scaleX(var(--p));
}

.uvq01-hld:hover .f {
  transform: scaleX(max(var(--p),.035));
}

.uvq01-hld .ic {
  position: relative;
  display: grid;
  width: 1.25em;
  height: 1.25em;
}

.uvq01-hld svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.uvq01-hld .lid {
  transform-origin: 20px 7px;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq01-hld .w {
  position: relative;
  display: grid;
}

.uvq01-hld .t,.uvq01-hld .d {
  grid-area: 1/1;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),translate calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),visibility calc(0.25s / var(--k));
}

.uvq01-hld .d {
  opacity: 0;
  visibility: hidden;
  translate: 0 .7em;
}

.uvq01-hld.is-hold {
  transform: scale(.975);
}

.uvq01-hld.is-hold .lid {
  animation: uvq01-hld-lid calc(0.16s / var(--k)) linear infinite;
}

.uvq01-hld.is-done {
  background: var(--c1);
}

.uvq01-hld.is-done .t {
  opacity: 0;
  visibility: hidden;
  translate: 0 -.7em;
}

.uvq01-hld.is-done .d {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
}

.uvq01-hld.is-done .lid {
  transform: rotate(-38deg) translate(-2px,-3px);
}

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

@keyframes uvq01-hld-lid {
  0%,100% {
    transform: rotate(-8deg) translateY(-1px);
  }
  50% {
    transform: rotate(-16deg) translateY(-2.5px);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq01-hld,.uvq01-hld *,.uvq01-hld *::before,.uvq01-hld *::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) {
  let p=0,on=false,done=false,raf=0,last=0,tm=0;
const dur=()=>(parseFloat(getComputedStyle(el).getPropertyValue("--hold"))||1.4)*1000;
const tick=t=>{const dt=last?Math.min(64,t-last):16;last=t;p=Math.max(0,Math.min(1,on?p+dt/dur():p-dt/320));el.style.setProperty("--p",p.toFixed(3));
if(on&&p>=1){on=false;done=true;raf=0;last=0;el.classList.remove("is-hold");el.classList.add("is-done");tm=setTimeout(()=>{done=false;el.classList.remove("is-done");raf=requestAnimationFrame(tick)},1800);return}
if(on||p>0)raf=requestAnimationFrame(tick);else{raf=0;last=0}};
const run=()=>{if(!raf){last=0;raf=requestAnimationFrame(tick)}};
const start=()=>{if(done||on)return;on=true;el.classList.add("is-hold");run()};
const stop=()=>{if(!on)return;on=false;el.classList.remove("is-hold");run()};
el.addEventListener("pointerdown",e=>{if(e.button)return;try{el.setPointerCapture(e.pointerId)}catch(_){}start()});
el.addEventListener("pointerup",stop);el.addEventListener("pointercancel",stop);el.addEventListener("lostpointercapture",stop);
el.addEventListener("keydown",e=>{if(e.key===" "||e.key==="Enter"){e.preventDefault();if(!e.repeat)start()}});
el.addEventListener("keyup",e=>{if(e.key===" "||e.key==="Enter")stop()});
el.addEventListener("blur",stop);el.addEventListener("contextmenu",e=>e.preventDefault());
return()=>{cancelAnimationFrame(raf);clearTimeout(tm)}
}

export default function BtnHoldDelete() {
  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": "#e5383b",
          "--c2": "#232227",
          "--s": "16px",
          "--k": "1",
          "--hold": "1.4",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <button className="uvq01-hld" type="button"><span className="f" aria-hidden="true"></span><span className="ic" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><g className="lid"><path d="M4 7h16" /><path d="M9.5 7V4.5h5V7" /></g><path d="M6 7l1 13h10l1-13" /><path d="M10 11v5M14 11v5" /></svg></span><span className="w"><span className="t">Hold to delete</span><span className="d">Deleted</span></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.
````
