SolutionsCase StudiesAI ToolsResourcesAboutContact
Get Your Free AI Automation Audit Book a Free 30-Minute Strategy Call
Playground~/frontend Open editor

~/css/tailwind-close-buttons

6 Tailwind Close Buttons

6 TailwindPublished 2026-10-04Free · no sign-up

Six close buttons in Tailwind: a round SVG X, a rotating dark button, a labelled pill with an Esc hint, a dismissible alert, ghost, soft and solid variants, and a close button that stays visible over photos.

01. Tailwind Round Close Button

TailwindButton

A round close button with an SVG cross, a hover tint and a focus ring, all in Tailwind classes. aria-label="Close" names the icon-only button, and h-10 w-10 gives a comfortable target on touch screens.

View code
<button aria-label="Close" class="grid h-10 w-10 place-items-center rounded-full bg-slate-100 text-slate-700 hover:bg-slate-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>

02. Tailwind Spinning Close Button

TailwindAnimation

A dark close button that rotates 90 degrees on hover and focus with hover:rotate-90 and a transition. motion-reduce:transform-none keeps it still for people who prefer less motion, while the colour change still signals interaction.

View code
<button aria-label="Close panel" class="grid h-11 w-11 place-items-center rounded-xl border border-slate-700 bg-slate-900 text-slate-200 transition hover:rotate-90 hover:border-red-400 focus-visible:rotate-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-400 motion-reduce:transform-none"><svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>

03. Tailwind Close with Label

TailwindUsability

A pill button with an X and the word Close plus an Esc hint in a kbd element. The visible text is the accessible name, which is clearer than an icon alone, and the shortcut hint teaches keyboard users a faster way out.

View code
<button class="inline-flex items-center gap-2 rounded-full border border-slate-300 bg-white px-3.5 py-2 text-sm font-semibold text-slate-900 hover:bg-slate-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"><span aria-hidden="true" class="text-lg leading-none">&times;</span> Close <kbd class="rounded border border-b-2 border-slate-300 px-1.5 font-mono text-[11px] text-slate-600">Esc</kbd></button>

04. Tailwind Dismissible Alert

TailwindAlert

A warning alert with a close button in its top corner. The button is named Dismiss warning, and the inline handler removes the alert; in an app you would also remember the dismissal so it does not come back on reload.

View code
<div role="alert" class="relative w-full max-w-sm rounded-xl border border-amber-300 bg-amber-50 p-4 pr-12 text-sm text-amber-900">
  <b class="block">Stock is running low</b>Only 3 units left of the linen tote.
  <button aria-label="Dismiss warning" onclick="this.parentElement.remove()" class="absolute right-2 top-2 grid h-8 w-8 place-items-center rounded-lg text-amber-800 hover:bg-amber-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-amber-700">&times;</button>
</div>

05. Tailwind Close Button Variants

TailwindVariants

Ghost, soft and solid close buttons in three sizes, showing which utilities change: size, background and text colour. The same SVG path is reused, scaled by the h-* and w-* utilities on the icon.

View code
<div class="flex items-center gap-4">
  <button aria-label="Close" class="grid h-8 w-8 place-items-center rounded-lg text-slate-300 hover:bg-slate-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"><svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>
  <button aria-label="Close" class="grid h-10 w-10 place-items-center rounded-xl bg-red-500/15 text-red-300 hover:bg-red-500/25 focus-visible:outline focus-visible:outline-2 focus-visible:outline-red-300"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>
  <button aria-label="Close" class="grid h-12 w-12 place-items-center rounded-2xl bg-white text-slate-900 hover:bg-slate-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"><svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>
</div>

06. Tailwind Close over Image

TailwindLightbox

A close button over a picture with a translucent dark background, a white ring and backdrop-blur, so it stays visible on light or dark photos. The figure has a caption and the image placeholder has a description.

View code
<figure class="relative w-full max-w-xs">
  <div role="img" aria-label="Snowy mountain at sunrise" class="aspect-[4/3] rounded-2xl bg-gradient-to-b from-sky-200 via-rose-100 to-white"></div>
  <button aria-label="Close image" class="absolute right-2.5 top-2.5 grid h-10 w-10 place-items-center rounded-full bg-slate-950/60 text-white ring-2 ring-white/80 backdrop-blur focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-300">&times;</button>
  <figcaption class="mt-2 text-sm text-slate-400">Sunrise on the ridge</figcaption>
</figure>

About these Tailwind Close Buttons

Icon buttons need names

Every icon-only close button has an aria-label. The SVG is aria-hidden and uses currentColor, so text colour utilities recolour it.

Hover motion

hover:rotate-90 with a transition gives a playful spin, and motion-reduce:transform-none removes it for people who prefer less motion.

Visible over photos

bg-slate-950/60, a white ring and backdrop-blur keep the button readable over light or dark images.

Focus rings

focus-visible:outline utilities give keyboard users a clear ring without showing it on mouse clicks.

Frequently asked questions

Do these need JavaScript?

Only the dismissible alert, to remove itself.

Which Tailwind version?

v3.4 or v4.

Is there a CSS version?

Yes, see the CSS close buttons collection.