Let’s create a Shredder Delete Button using HTML, CSS, and JavaScript – a blue delete button that works like a real paper shredder. When you click it, a document gets pulled into the slot, comes out the bottom cut into strips, and the button shows a live percentage before switching to a clean “Deleted” state.
- HTML: Create the button with a paper slot, a status light, cutter teeth and three label states (Delete, Shredding and Deleted). Add a small paper sheet above it with a PDF tag, file name, text lines and a “TOP SECRET” stamp, plus an empty area below where the strips come out.
- CSS: Style the cobalt blue button with a pressed bottom edge and a soft blue shadow on an ice grey-blue page. Use
clip-pathto hide the paper below the slot and the strips above the teeth, and add hover lift, a peeking paper, a tilting trash lid, a shaking motor effect, blinking light and a check mark that draws itself. - JavaScript: Control the whole shredding sequence with the Web Animations API. Pull the paper into the slot, cut it into 9 strips that each show their own slice of the page, count from 0% to 100%, throw out small paper bits, then let the strips fall away and reset the button.
This project teaches how to build a satisfying shredder delete button using HTML, CSS, and JavaScript by combining clip-path masking, cloned DOM slices, the Web Animations API and simple state-based CSS.
HTML :
HTML: Creates the structure of the shredder delete button, including the paper sheet waiting above the slot, the button with its light, teeth and three label states, and the empty zone where the shredded strips appear.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shredder Delete Button | @coding.stella</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main class="scene">
<div class="wrap" data-state="idle">
<div class="paper-zone">
<div class="paper sheet">
<div class="p-head"><span class="p-ext">PDF</span></div>
<div class="p-name">invoice_final_v2.pdf</div>
<div class="p-line" style="width:70%"></div>
<div class="p-line" style="width:84%"></div>
<div class="p-line" style="width:60%"></div>
<div class="p-stamp">TOP SECRET</div>
<div class="p-line" style="width:78%"></div>
<div class="p-line" style="width:50%"></div>
</div>
</div>
<button class="shredder" aria-label="Delete file">
<span class="slot"></span>
<span class="led"></span>
<span class="state s-idle">
<svg viewBox="0 0 24 24">
<g class="lid"><path d="M3 6h18"/><path d="M9 6V4h6v2"/></g>
<path d="M5 6l1 14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-14"/>
<path d="M10 11v6M14 11v6"/>
</svg>
<span>Delete</span>
</span>
<span class="state s-busy">
<span class="bars"><i></i><i></i><i></i></span>
<span>Shredding <b class="pct">0%</b></span>
</span>
<span class="state s-done">
<svg class="check" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
<span>Deleted</span>
</span>
<span class="teeth"></span>
</button>
<div class="strip-zone"></div>
</div>
<p class="sr-only" aria-live="polite" id="status"></p>
</main>
<p class="hint">Click to delete. Oddly satisfying.</p>
<script src="script.js"></script>
</body>
</html>
CSS :
CSS: Styles the blue shredder button and the paper, hides the paper and strips with clip-path so they look like they pass through the machine, and adds the hover, shaking, blinking, label and success animations. All colours and sizes live in CSS variables at the top.
:root {
--bg: #e7ecf3;
--muted: #7d8aa3;
--blue-top: #3a76ff;
--blue: #1f56e0;
--blue-edge: #1442b4;
--blue-deep: #0b1d52;
--on-blue: #ffffff;
--on-blue-dim: rgba(255, 255, 255, 0.72);
--led-off: rgba(255, 255, 255, 0.28);
--paper: #ffffff;
--ink: #0f1c36;
--line: #e3e8f0;
--chad: #b4c0d4;
--accent: #2f6bff;
--shadow: rgba(31, 86, 224, 0.4);
--shadow-soft: rgba(20, 40, 80, 0.12);
--btn-w: 240px;
--btn-h: 72px;
--paper-w: 100px;
--paper-h: 128px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
min-height: 100vh;
display: grid;
place-items: center;
font-family: "Poppins", system-ui, sans-serif;
color: var(--ink);
background: var(--bg);
overflow: hidden;
}
.scene {
position: relative;
}
.wrap {
position: relative;
margin: 170px 0 280px;
}
.shredder {
position: relative;
z-index: 2;
width: var(--btn-w);
height: var(--btn-h);
border: none;
border-radius: 16px;
cursor: pointer;
color: var(--on-blue);
font: 500 18px "Poppins", sans-serif;
letter-spacing: 0.2px;
background: linear-gradient(180deg, var(--blue-top) 0%, var(--blue) 100%);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.28),
inset 0 -4px 0 rgba(8, 30, 110, 0.35),
0 2px 0 var(--blue-edge),
0 22px 30px -14px var(--shadow);
transition: transform 0.15s, box-shadow 0.15s;
-webkit-tap-highlight-color: transparent;
}
.wrap[data-state="idle"] .shredder:hover {
transform: translateY(-2px);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.28),
inset 0 -4px 0 rgba(8, 30, 110, 0.35),
0 4px 0 var(--blue-edge),
0 28px 34px -14px var(--shadow);
}
.wrap[data-state="idle"] .shredder:active {
transform: translateY(2px);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.28),
inset 0 -2px 0 rgba(8, 30, 110, 0.35),
0 0 0 var(--blue-edge),
0 12px 20px -12px var(--shadow);
}
.shredder:focus-visible {
outline: 2px solid var(--blue);
outline-offset: 5px;
}
.slot {
position: absolute;
top: -3px;
left: 50%;
width: calc(var(--paper-w) + 12px);
height: 7px;
transform: translateX(-50%);
border-radius: 4px;
background: var(--blue-deep);
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.6);
z-index: 3;
}
.teeth {
position: absolute;
bottom: -6px;
left: 50%;
width: calc(var(--paper-w) + 12px);
height: 9px;
transform: translateX(-50%);
border-radius: 0 0 5px 5px;
background: repeating-linear-gradient(90deg, #c9d8ff 0 5px, var(--blue-deep) 5px 7px);
z-index: 3;
}
.led {
position: absolute;
top: 12px;
right: 14px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--led-off);
z-index: 3;
transition: background 0.2s;
}
.wrap[data-state="idle"] .shredder:hover .led,
.wrap[data-state="done"] .led {
background: var(--on-blue);
}
.wrap[data-state="busy"] .led {
animation: blink 0.18s steps(2) infinite;
}
@keyframes blink {
0% { background: var(--on-blue); }
100% { background: var(--led-off); }
}
.state {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
z-index: 2;
opacity: 0;
transform: translateY(14px);
transition: opacity 0.25s, transform 0.4s cubic-bezier(0.2, 1.3, 0.4, 1);
pointer-events: none;
}
.wrap[data-state="idle"] .s-idle,
.wrap[data-state="busy"] .s-busy,
.wrap[data-state="done"] .s-done {
opacity: 1;
transform: none;
}
.s-busy {
color: var(--on-blue-dim);
font-size: 16px;
}
.pct {
display: inline-block;
min-width: 44px;
color: var(--on-blue);
font-weight: 600;
font-variant-numeric: tabular-nums;
}
svg {
width: 22px;
height: 22px;
fill: none;
stroke: currentColor;
stroke-width: 2.2;
stroke-linecap: round;
stroke-linejoin: round;
overflow: visible;
}
.lid {
transform-origin: 19px 6px;
transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.wrap[data-state="idle"] .shredder:hover .lid {
transform: rotate(18deg) translateY(-2px);
}
.check {
width: 24px;
height: 24px;
stroke-width: 3;
stroke-dasharray: 24;
stroke-dashoffset: 24;
}
.wrap[data-state="done"] .check {
animation: draw 0.45s 0.15s cubic-bezier(0.6, 0, 0.3, 1) forwards;
}
@keyframes draw {
to { stroke-dashoffset: 0; }
}
.bars {
display: flex;
align-items: flex-end;
gap: 3px;
height: 16px;
}
.bars i {
width: 3px;
height: 100%;
border-radius: 2px;
background: var(--on-blue);
animation: eq 0.4s ease-in-out infinite alternate;
}
.bars i:nth-child(2) { animation-delay: -0.15s; }
.bars i:nth-child(3) { animation-delay: -0.3s; }
@keyframes eq {
from { transform: scaleY(0.3); }
to { transform: scaleY(1); }
}
.wrap[data-state="busy"] .shredder {
animation: buzz 0.07s linear infinite;
cursor: progress;
}
@keyframes buzz {
0%, 100% { transform: translate(0, 0); }
25% { transform: translate(1px, -1px); }
50% { transform: translate(-1px, 1px); }
75% { transform: translate(1px, 1px); }
}
.wrap[data-state="done"] .shredder {
cursor: default;
animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
0%, 100% { transform: scale(1); }
40% { transform: scale(1.06); }
}
.paper-zone {
position: absolute;
left: 50%;
bottom: 100%;
width: var(--paper-w);
height: 160px;
transform: translateX(-50%);
clip-path: inset(-300px -300px 0 -300px);
pointer-events: none;
z-index: 1;
}
.paper {
position: absolute;
top: 100%;
left: 0;
transition: transform 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@media (hover: hover) {
.wrap[data-state="idle"]:hover .paper {
transform: translateY(-38px);
}
}
.wrap[data-state="idle"]:focus-within .paper {
transform: translateY(-38px);
}
.sheet {
width: var(--paper-w);
height: var(--paper-h);
background: var(--paper);
border-radius: 3px 3px 0 0;
box-shadow: 0 0 0 1px rgba(15, 28, 54, 0.06), 0 -2px 8px var(--shadow-soft);
overflow: hidden;
color: var(--ink);
}
.p-head {
height: 24px;
display: flex;
align-items: center;
padding: 0 8px;
border-bottom: 1px solid var(--line);
}
.p-ext {
font-size: 7px;
font-weight: 700;
color: #fff;
background: var(--accent);
padding: 1px 4px;
border-radius: 2px;
letter-spacing: 0.8px;
}
.p-name {
font-size: 7.5px;
font-weight: 600;
margin: 7px 8px 6px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.p-line {
height: 4px;
margin: 6px 8px;
border-radius: 2px;
background: var(--line);
}
.p-stamp {
display: inline-block;
margin: 3px 0 2px 18px;
padding: 2px 5px;
font-size: 7px;
font-weight: 700;
letter-spacing: 1px;
color: var(--accent);
border: 1.5px solid var(--accent);
border-radius: 3px;
transform: rotate(-10deg);
}
.strip-zone {
position: absolute;
left: 50%;
top: 100%;
width: var(--paper-w);
height: var(--paper-h);
transform: translateX(-50%);
clip-path: inset(0 -400px -800px -400px);
pointer-events: none;
z-index: 1;
}
.strip {
position: absolute;
top: 0;
height: var(--paper-h);
overflow: hidden;
transform: translateY(calc(var(--paper-h) * -1));
will-change: transform, opacity;
box-shadow: 0 0 0 0.5px rgba(15, 28, 54, 0.08), 0 3px 6px var(--shadow-soft);
}
.strip .sheet {
position: absolute;
top: 0;
box-shadow: none;
border-radius: 0;
}
.chad {
position: absolute;
top: 2px;
border-radius: 1px;
background: var(--chad);
pointer-events: none;
}
.hint {
position: fixed;
bottom: 28px;
left: 0;
right: 0;
text-align: center;
font-size: 13px;
color: var(--muted);
letter-spacing: 0.3px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
@media (max-width: 380px) {
.wrap {
transform: scale(0.88);
}
}
@media (prefers-reduced-motion: reduce) {
.wrap[data-state="busy"] .shredder,
.wrap[data-state="done"] .shredder {
animation: none;
}
}
JavaScript:
JavaScript: Handles the click, moves the paper into the slot, builds the strips by cloning the paper and shifting each copy, updates the percentage, spawns the paper bits, drops the strips and resets the shredder delete button when it is done.
const wrap = document.querySelector(".wrap");
const btn = document.querySelector(".shredder");
const paper = document.querySelector(".paper");
const stripZone = document.querySelector(".strip-zone");
const pctEl = document.querySelector(".pct");
const statusEl = document.getElementById("status");
const STRIPS = 9;
const W = 100;
const H = 128;
const SHRED_TIME = 1900;
const FEED_DELAY = 160;
const RESET_AFTER = 1800;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const rand = (min, max) => Math.random() * (max - min) + min;
function buildStrips() {
const sw = W / STRIPS;
stripZone.innerHTML = "";
return Array.from({ length: STRIPS }, (_, i) => {
const strip = document.createElement("div");
strip.className = "strip";
strip.style.left = `${i * sw}px`;
strip.style.width = `${sw - 1}px`;
const slice = paper.cloneNode(true);
slice.className = "sheet";
slice.style.cssText = `left:${-i * sw}px`;
strip.appendChild(slice);
stripZone.appendChild(strip);
return strip;
});
}
function spawnChad() {
const chad = document.createElement("div");
chad.className = "chad";
chad.style.left = `${rand(4, W - 4)}px`;
chad.style.width = `${rand(2, 4)}px`;
chad.style.height = `${rand(3, 6)}px`;
stripZone.appendChild(chad);
chad.animate(
[
{ transform: "translate(0, 0) rotate(0deg)", opacity: 1 },
{ transform: `translate(${rand(-60, 60)}px, ${rand(120, 230)}px) rotate(${rand(-360, 360)}deg)`, opacity: 0 },
],
{ duration: rand(600, 1000), easing: "cubic-bezier(.3,.1,.7,1)" }
).onfinish = () => chad.remove();
}
function movePaper(from, to, duration, easing) {
return paper.animate(
[{ transform: `translateY(${from}px)` }, { transform: `translateY(${to}px)` }],
{ duration, easing, fill: "forwards" }
).finished;
}
async function shred() {
if (wrap.dataset.state !== "idle") return;
wrap.dataset.state = "busy";
statusEl.textContent = "Deleting file";
const startY = new DOMMatrix(getComputedStyle(paper).transform).m42;
await movePaper(startY, -H - 14, 300, "cubic-bezier(.2,.9,.3,1.25)");
await movePaper(-H - 14, -H, 110, "ease-in");
const strips = buildStrips();
movePaper(-H, 0, SHRED_TIME, "linear");
const feeding = strips.map((s) =>
s.animate(
[{ transform: `translateY(${-H}px)` }, { transform: "translateY(0)" }],
{ duration: SHRED_TIME, delay: FEED_DELAY, easing: "linear", fill: "forwards" }
).finished
);
const t0 = performance.now();
const total = SHRED_TIME + FEED_DELAY;
requestAnimationFrame(function tick(now) {
const p = Math.min(1, (now - t0) / total);
pctEl.textContent = `${Math.round(p * 100)}%`;
if (p < 1) requestAnimationFrame(tick);
});
await sleep(FEED_DELAY);
const chads = setInterval(() => {
spawnChad();
if (Math.random() > 0.5) spawnChad();
}, 45);
await Promise.all(feeding);
clearInterval(chads);
wrap.dataset.state = "done";
statusEl.textContent = "File deleted";
const mid = (STRIPS - 1) / 2;
await Promise.all(
strips.map((s, i) =>
s.animate(
[
{ transform: "translate(0, 0) rotate(0deg)", opacity: 1 },
{ transform: `translate(${(i - mid) * rand(3, 9)}px, ${rand(30, 60)}px) rotate(${(i - mid) * rand(1, 3)}deg)`, opacity: 1, offset: 0.35 },
{ transform: `translate(${(i - mid) * rand(10, 22)}px, ${rand(220, 320)}px) rotate(${rand(-40, 40)}deg)`, opacity: 0 },
],
{ duration: rand(900, 1300), delay: rand(0, 160), easing: "cubic-bezier(.45,0,.8,.6)", fill: "forwards" }
).finished
)
);
stripZone.innerHTML = "";
await sleep(RESET_AFTER);
paper.getAnimations().forEach((a) => a.cancel());
pctEl.textContent = "0%";
statusEl.textContent = "";
wrap.dataset.state = "idle";
}
btn.addEventListener("click", shred);
This project demonstrates how HTML, CSS, and JavaScript can work together to turn a plain delete button into a small story. The paper slides in, comes out as real strips, and the button confirms the action with a clear “Deleted” state. You can reuse the same strip slicing idea for other playful buttons, like a paper shredder for a trash folder or a cancel action in your own projects.
If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!
