Pure TailwindMIT licensed

Trash Compactor Tailwind Close Button

A little machine: on hover two steel plates slam inward with group-hover:translate-y-[15px] while the × is crushed flat by scale-y-22 and bows out with scale-x-125. One anticipation curve, declared once in @theme as --ease-tcb17-crush, drives every part, so the plates and the glyph move as a single mechanism.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<section class="tcb-17 w-full min-h-svh grid place-items-center bg-[linear-gradient(180deg,var(--color-tcb17-bg),var(--color-tcb17-bg2))] px-6 py-12 font-tcb17-sans" aria-label="Trash compactor close button demo">
  <div class="grid w-full justify-items-center gap-7">
    <button type="button" aria-label="Close" class="group relative grid size-19 cursor-pointer place-items-center overflow-hidden rounded-[14px] border border-tcb17-edge/60 bg-linear-to-b from-tcb17-h1 to-tcb17-h2 shadow-[0_16px_36px_-18px_rgb(0_0_0/0.85),inset_0_1px_0_var(--color-tcb17-hl)] focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-tcb17-ring active:scale-95">
      <span aria-hidden="true" class="absolute inset-x-2.5 top-2 h-2 rounded-[3px] bg-linear-to-b from-tcb17-steel to-tcb17-steel2 shadow-[0_2px_4px_rgb(0_0_0/0.5)] transition-[translate] duration-340 ease-tcb17-crush group-hover:translate-y-[15px] group-focus-visible:translate-y-[15px] motion-reduce:transition-none"></span>
      <span aria-hidden="true" class="relative size-6 transition-[scale] duration-340 ease-tcb17-crush before:absolute before:top-1/2 before:left-1/2 before:h-[3px] before:w-6 before:-translate-1/2 before:rotate-45 before:rounded-[2px] before:bg-tcb17-x after:absolute after:top-1/2 after:left-1/2 after:h-[3px] after:w-6 after:-translate-1/2 after:-rotate-45 after:rounded-[2px] after:bg-tcb17-x group-hover:scale-x-125 group-hover:scale-y-22 group-focus-visible:scale-x-125 group-focus-visible:scale-y-22 motion-reduce:transition-none"></span>
      <span aria-hidden="true" class="absolute inset-x-2.5 bottom-2 h-2 rounded-[3px] bg-linear-to-b from-tcb17-steel to-tcb17-steel2 shadow-[0_2px_4px_rgb(0_0_0/0.5)] transition-[translate] duration-340 ease-tcb17-crush group-hover:-translate-y-[15px] group-focus-visible:-translate-y-[15px] motion-reduce:transition-none"></span>
    </button>
    <p aria-hidden="true" class="rounded-full px-3.5 py-2 font-tcb17-mono text-[11.5px] text-tcb17-mut ring-1 ring-white/12">ease-tcb17-crush · group-hover:scale-y-22 · translate-y-[15px]</p>
  </div>
</section>
@import "tailwindcss";

@theme {
  --color-tcb17-bg: #2d3139;
  --color-tcb17-bg: oklch(0.32 0.02 255);
  --color-tcb17-bg2: #1c1f25;
  --color-tcb17-bg2: oklch(0.22 0.015 250);
  --color-tcb17-h1: #4a4f59;
  --color-tcb17-h1: oklch(0.4 0.02 250);
  --color-tcb17-h2: #33373f;
  --color-tcb17-h2: oklch(0.3 0.02 250);
  --color-tcb17-hl: #6b717c80;
  --color-tcb17-hl: oklch(0.55 0.02 250 / 0.5);
  --color-tcb17-edge: #666b75;
  --color-tcb17-edge: oklch(0.5 0.02 250);
  --color-tcb17-steel: #b4b9c2;
  --color-tcb17-steel: oklch(0.75 0.02 250);
  --color-tcb17-steel2: #797e88;
  --color-tcb17-steel2: oklch(0.55 0.02 250);
  --color-tcb17-x: #e5e8ec;
  --color-tcb17-x: oklch(0.92 0.01 250);
  --color-tcb17-ring: #a7c3ec;
  --color-tcb17-ring: oklch(0.8 0.1 250);
  --color-tcb17-mut: #b3b8c2;
  --color-tcb17-mut: oklch(0.77 0.02 250);
  --font-tcb17-sans: 'Geist', system-ui, sans-serif;
  --font-tcb17-mono: 'Geist Mono', ui-monospace, monospace;
  --ease-tcb17-crush: cubic-bezier(0.6, -.28, 0.55, 1.32);
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.tcb-17 {
  width: 100%;
  min-height: 100svh;
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-tcb17-bg: #2d3139;
  --color-tcb17-bg: oklch(0.32 0.02 255);
  --color-tcb17-bg2: #1c1f25;
  --color-tcb17-bg2: oklch(0.22 0.015 250);
  --color-tcb17-h1: #4a4f59;
  --color-tcb17-h1: oklch(0.4 0.02 250);
  --color-tcb17-h2: #33373f;
  --color-tcb17-h2: oklch(0.3 0.02 250);
  --color-tcb17-hl: #6b717c80;
  --color-tcb17-hl: oklch(0.55 0.02 250 / 0.5);
  --color-tcb17-edge: #666b75;
  --color-tcb17-edge: oklch(0.5 0.02 250);
  --color-tcb17-steel: #b4b9c2;
  --color-tcb17-steel: oklch(0.75 0.02 250);
  --color-tcb17-steel2: #797e88;
  --color-tcb17-steel2: oklch(0.55 0.02 250);
  --color-tcb17-x: #e5e8ec;
  --color-tcb17-x: oklch(0.92 0.01 250);
  --color-tcb17-ring: #a7c3ec;
  --color-tcb17-ring: oklch(0.8 0.1 250);
  --color-tcb17-mut: #b3b8c2;
  --color-tcb17-mut: oklch(0.77 0.02 250);
  --font-tcb17-sans: 'Geist', system-ui, sans-serif;
  --font-tcb17-mono: 'Geist Mono', ui-monospace, monospace;
  --ease-tcb17-crush: cubic-bezier(0.6, -.28, 0.55, 1.32);
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.tcb-17 {
  width: 100%;
  min-height: 100svh;
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400..800&family=Geist+Mono:wght@400..600&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • The --ease custom property became an @theme entry, --ease-tcb17-crush, which v4 turns into the ease-tcb17-crush utility.
  • --crush:.22 became scale-y-22; the hover rules no longer restate the bars' centring transforms.
  • UI upgrade from the CSS original: keyboard focus runs the compactor too, and the stage caption rose to 7:1 on the dark steel background.
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 demo 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: Trash Compactor Tailwind Close Button
Source: https://codefronts.com/components/tailwind-css-close-buttons/trash-compactor/

A little machine: on hover two steel plates slam inward with group-hover:translate-y-[15px] while the × is crushed flat by scale-y-22 and bows out with scale-x-125. One anticipation curve, declared once in @theme as --ease-tcb17-crush, drives every part, so the plates and the glyph move as a single mechanism.
## HTML
```html
<section class="tcb-17 w-full min-h-svh grid place-items-center bg-[linear-gradient(180deg,var(--color-tcb17-bg),var(--color-tcb17-bg2))] px-6 py-12 font-tcb17-sans" aria-label="Trash compactor close button demo">
  <div class="grid w-full justify-items-center gap-7">
    <button type="button" aria-label="Close" class="group relative grid size-19 cursor-pointer place-items-center overflow-hidden rounded-[14px] border border-tcb17-edge/60 bg-linear-to-b from-tcb17-h1 to-tcb17-h2 shadow-[0_16px_36px_-18px_rgb(0_0_0/0.85),inset_0_1px_0_var(--color-tcb17-hl)] focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-tcb17-ring active:scale-95">
      <span aria-hidden="true" class="absolute inset-x-2.5 top-2 h-2 rounded-[3px] bg-linear-to-b from-tcb17-steel to-tcb17-steel2 shadow-[0_2px_4px_rgb(0_0_0/0.5)] transition-[translate] duration-340 ease-tcb17-crush group-hover:translate-y-[15px] group-focus-visible:translate-y-[15px] motion-reduce:transition-none"></span>
      <span aria-hidden="true" class="relative size-6 transition-[scale] duration-340 ease-tcb17-crush before:absolute before:top-1/2 before:left-1/2 before:h-[3px] before:w-6 before:-translate-1/2 before:rotate-45 before:rounded-[2px] before:bg-tcb17-x after:absolute after:top-1/2 after:left-1/2 after:h-[3px] after:w-6 after:-translate-1/2 after:-rotate-45 after:rounded-[2px] after:bg-tcb17-x group-hover:scale-x-125 group-hover:scale-y-22 group-focus-visible:scale-x-125 group-focus-visible:scale-y-22 motion-reduce:transition-none"></span>
      <span aria-hidden="true" class="absolute inset-x-2.5 bottom-2 h-2 rounded-[3px] bg-linear-to-b from-tcb17-steel to-tcb17-steel2 shadow-[0_2px_4px_rgb(0_0_0/0.5)] transition-[translate] duration-340 ease-tcb17-crush group-hover:-translate-y-[15px] group-focus-visible:-translate-y-[15px] motion-reduce:transition-none"></span>
    </button>
    <p aria-hidden="true" class="rounded-full px-3.5 py-2 font-tcb17-mono text-[11.5px] text-tcb17-mut ring-1 ring-white/12">ease-tcb17-crush · group-hover:scale-y-22 · translate-y-[15px]</p>
  </div>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-tcb17-bg: #2d3139;
  --color-tcb17-bg: oklch(0.32 0.02 255);
  --color-tcb17-bg2: #1c1f25;
  --color-tcb17-bg2: oklch(0.22 0.015 250);
  --color-tcb17-h1: #4a4f59;
  --color-tcb17-h1: oklch(0.4 0.02 250);
  --color-tcb17-h2: #33373f;
  --color-tcb17-h2: oklch(0.3 0.02 250);
  --color-tcb17-hl: #6b717c80;
  --color-tcb17-hl: oklch(0.55 0.02 250 / 0.5);
  --color-tcb17-edge: #666b75;
  --color-tcb17-edge: oklch(0.5 0.02 250);
  --color-tcb17-steel: #b4b9c2;
  --color-tcb17-steel: oklch(0.75 0.02 250);
  --color-tcb17-steel2: #797e88;
  --color-tcb17-steel2: oklch(0.55 0.02 250);
  --color-tcb17-x: #e5e8ec;
  --color-tcb17-x: oklch(0.92 0.01 250);
  --color-tcb17-ring: #a7c3ec;
  --color-tcb17-ring: oklch(0.8 0.1 250);
  --color-tcb17-mut: #b3b8c2;
  --color-tcb17-mut: oklch(0.77 0.02 250);
  --font-tcb17-sans: 'Geist', system-ui, sans-serif;
  --font-tcb17-mono: 'Geist Mono', ui-monospace, monospace;
  --ease-tcb17-crush: cubic-bezier(0.6, -.28, 0.55, 1.32);
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.tcb-17 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Name the curve, reuse the curve. The CSS original kept a --ease variable; in v4 an --ease-* theme entry is a utility:

@theme { --ease-tcb17-crush: cubic-bezier(.6,-.28,.55,1.32); }
<span class="… duration-340 ease-tcb17-crush group-hover:translate-y-[15px]">

The negative first handle winds the plates back before they strike; the >1 second handle lets them bounce off the glyph.

Make it yours

  • Harder crush: scale-y-10.
  • Horizontal compactor: rotate the housing rotate-90 and counter-rotate the glyph.
  • Colour-coded danger: tint plates with a red token on destructive dialogs.

Gotchas — read before shipping

  • scale-y-22 means 22% — v4 accepts any integer percentage without brackets.
  • Scaling a pseudo-element's parent scales the bars' thickness too; that squash is the effect.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

The floor is Tailwind v4's generated sheet.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Search CodeFronts

Loading…