Pure TailwindMIT licensed

Rotate on Hover Tailwind Close Button

The most-searched close-button animation, done cleanly: a 180° group-hover:rotate-180 on the glyph with an ease-out-expo curve, the ring and bars shifting to the accent. grid place-items-center kills the sub-pixel wobble that plagues spinning icons, and v4's hover: is already gated behind @media (hover:hover) — the original's hand-written media query simply disappears.

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-13 w-full min-h-svh grid place-items-center bg-[linear-gradient(180deg,var(--color-tcb13-bg),var(--color-tcb13-bg2))] px-6 py-12 font-tcb13-sans" aria-label="Rotate on hover close button demo">
  <div class="grid w-full justify-items-center gap-7">
    <button type="button" aria-label="Close" class="group grid size-15 cursor-pointer place-items-center rounded-full border-2 border-tcb13-ink/30 bg-white shadow-[0_12px_28px_-16px_var(--color-tcb13-shadow)] transition duration-250 hover:border-tcb13-acc focus-visible:border-tcb13-acc focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-tcb13-acc active:scale-92 motion-reduce:transition-none">
      <span aria-hidden="true" class="relative size-5.5 transition-transform duration-450 ease-[cubic-bezier(.22,1,.36,1)] before:absolute before:top-1/2 before:left-1/2 before:h-[2.5px] before:w-5.5 before:-translate-1/2 before:rotate-45 before:rounded-full before:bg-tcb13-ink before:transition-colors before:duration-250 after:absolute after:top-1/2 after:left-1/2 after:h-[2.5px] after:w-5.5 after:-translate-1/2 after:-rotate-45 after:rounded-full after:bg-tcb13-ink after:transition-colors after:duration-250 group-hover:rotate-180 group-hover:before:bg-tcb13-acc group-hover:after:bg-tcb13-acc group-focus-visible:rotate-180 motion-reduce:transition-none"></span>
    </button>
    <p aria-hidden="true" class="rounded-full bg-white/70 px-3.5 py-2 font-tcb13-mono text-[11.5px] text-tcb13-mut ring-1 ring-black/8">group-hover:rotate-180 · ease-[cubic-bezier(.22,1,.36,1)]</p>
  </div>
</section>
@import "tailwindcss";

@theme {
  --color-tcb13-bg: #f5f6fa;
  --color-tcb13-bg: oklch(0.97 0.006 265);
  --color-tcb13-bg2: #e8e9f2;
  --color-tcb13-bg2: oklch(0.93 0.014 265);
  --color-tcb13-ink: #3a3e52;
  --color-tcb13-ink: oklch(0.35 0.03 265);
  --color-tcb13-mut: #555a70;
  --color-tcb13-mut: oklch(0.46 0.03 265);
  --color-tcb13-acc: #4150d8;
  --color-tcb13-acc: oklch(0.52 0.19 268);
  --color-tcb13-shadow: #4a4f7080;
  --color-tcb13-shadow: oklch(0.4 0.06 265 / 0.5);
  --font-tcb13-sans: 'Geist', system-ui, sans-serif;
  --font-tcb13-mono: 'Geist Mono', ui-monospace, monospace;
}
/* 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-13 {
  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-tcb13-bg: #f5f6fa;
  --color-tcb13-bg: oklch(0.97 0.006 265);
  --color-tcb13-bg2: #e8e9f2;
  --color-tcb13-bg2: oklch(0.93 0.014 265);
  --color-tcb13-ink: #3a3e52;
  --color-tcb13-ink: oklch(0.35 0.03 265);
  --color-tcb13-mut: #555a70;
  --color-tcb13-mut: oklch(0.46 0.03 265);
  --color-tcb13-acc: #4150d8;
  --color-tcb13-acc: oklch(0.52 0.19 268);
  --color-tcb13-shadow: #4a4f7080;
  --color-tcb13-shadow: oklch(0.4 0.06 265 / 0.5);
  --font-tcb13-sans: 'Geist', system-ui, sans-serif;
  --font-tcb13-mono: 'Geist Mono', ui-monospace, monospace;
}
/* 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-13 {
  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 original's @media (hover:hover){…} block vanished: v4 compiles every hover: utility inside that query already.
  • color-mix(in oklab, var(--ink) 30%, transparent) became border-tcb13-ink/30.
  • UI upgrade from the CSS original: keyboard focus spins the glyph and colours the ring too, and the accent darkened slightly (0.55 → 0.52) so the focused border clears 5:1 on white.
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: Rotate on Hover Tailwind Close Button
Source: https://codefronts.com/components/tailwind-css-close-buttons/rotate-out/

The most-searched close-button animation, done cleanly: a 180° group-hover:rotate-180 on the glyph with an ease-out-expo curve, the ring and bars shifting to the accent. grid place-items-center kills the sub-pixel wobble that plagues spinning icons, and v4's hover: is already gated behind @media (hover:hover) — the original's hand-written media query simply disappears.
## HTML
```html
<section class="tcb-13 w-full min-h-svh grid place-items-center bg-[linear-gradient(180deg,var(--color-tcb13-bg),var(--color-tcb13-bg2))] px-6 py-12 font-tcb13-sans" aria-label="Rotate on hover close button demo">
  <div class="grid w-full justify-items-center gap-7">
    <button type="button" aria-label="Close" class="group grid size-15 cursor-pointer place-items-center rounded-full border-2 border-tcb13-ink/30 bg-white shadow-[0_12px_28px_-16px_var(--color-tcb13-shadow)] transition duration-250 hover:border-tcb13-acc focus-visible:border-tcb13-acc focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-tcb13-acc active:scale-92 motion-reduce:transition-none">
      <span aria-hidden="true" class="relative size-5.5 transition-transform duration-450 ease-[cubic-bezier(.22,1,.36,1)] before:absolute before:top-1/2 before:left-1/2 before:h-[2.5px] before:w-5.5 before:-translate-1/2 before:rotate-45 before:rounded-full before:bg-tcb13-ink before:transition-colors before:duration-250 after:absolute after:top-1/2 after:left-1/2 after:h-[2.5px] after:w-5.5 after:-translate-1/2 after:-rotate-45 after:rounded-full after:bg-tcb13-ink after:transition-colors after:duration-250 group-hover:rotate-180 group-hover:before:bg-tcb13-acc group-hover:after:bg-tcb13-acc group-focus-visible:rotate-180 motion-reduce:transition-none"></span>
    </button>
    <p aria-hidden="true" class="rounded-full bg-white/70 px-3.5 py-2 font-tcb13-mono text-[11.5px] text-tcb13-mut ring-1 ring-black/8">group-hover:rotate-180 · ease-[cubic-bezier(.22,1,.36,1)]</p>
  </div>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-tcb13-bg: #f5f6fa;
  --color-tcb13-bg: oklch(0.97 0.006 265);
  --color-tcb13-bg2: #e8e9f2;
  --color-tcb13-bg2: oklch(0.93 0.014 265);
  --color-tcb13-ink: #3a3e52;
  --color-tcb13-ink: oklch(0.35 0.03 265);
  --color-tcb13-mut: #555a70;
  --color-tcb13-mut: oklch(0.46 0.03 265);
  --color-tcb13-acc: #4150d8;
  --color-tcb13-acc: oklch(0.52 0.19 268);
  --color-tcb13-shadow: #4a4f7080;
  --color-tcb13-shadow: oklch(0.4 0.06 265 / 0.5);
  --font-tcb13-sans: 'Geist', system-ui, sans-serif;
  --font-tcb13-mono: 'Geist Mono', ui-monospace, monospace;
}
/* 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-13 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Rotate the wrapper, not the bars. The bars live on before:/after: with their own ±45°. Spinning the parent span 180° maps the × onto itself — it reads as a spin but ends exactly where it started, so there is no "wrong" resting angle if the pointer leaves mid-turn.

<span class="… transition-transform duration-450 ease-[cubic-bezier(.22,1,.36,1)]
  group-hover:rotate-180 group-focus-visible:rotate-180">

Make it yours

  • Quarter turn: rotate-90 reads snappier on small buttons.
  • Spin + shrink: add group-hover:scale-85.
  • Neutral hover: drop the accent classes to keep only the motion.

Gotchas — read before shipping

  • will-change is not needed for a one-shot transform; the original's hover-gated will-change was dropped.
  • Rotating an element with a non-integer centre causes shimmer — keep glyph spans at even pixel sizes.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

The floor is Tailwind v4's generated sheet.

Techniques used in this demo

Search CodeFronts

Loading…