A CSS close button is the small dismissal control that closes a modal, dialog, toast, or panel. These 18 hand-coded designs are ready-to-ship close controls for any overlay or banner — copy the markup, wire your dismiss handler, and ship.
The X is rendered as two thin paper-fold creases — on hover the button collapses inward via clip-path like an origami fold, leaving a tight diamond that vanishes.
A padlock chrome with a shackle that tumbles open on click — the X aligns into the lock body as it unlocks. Premium choice for "remove from saved" and "unlock to dismiss" flows.
Two stubby horizontal bars sit apart at rest — on hover they magnetically pull toward each other and snap into a perfect X. Hyper-clean micro-interaction.
A fully-fledged toast notification with an X — clicking slides the toast off-canvas to the right while fading, the way a real production toast behaves.
A conic-gradient vortex swirls slowly behind the X at rest, then accelerates dramatically on hover — the ultimate premium "this is special" close button.
Use a real button element with type='button' and an accessible name — either aria-label='Close' or visually-hidden text inside the button. Do not use a div or a bare span for a close (X) button: a button is keyboard-focusable, fires on Enter and Space, and is announced as a button by screen readers. The X glyph itself should be decorative (a pseudo-element or an aria-hidden icon) so assistive tech reads 'Close', not the character.
How do I make a pure CSS close (X) button without an icon font or image?
Draw the cross with two pseudo-elements. Give the button position: relative, then add ::before and ::after as thin bars (for example width: 2px, height: 60%) absolutely centred, and rotate one 45deg and the other -45deg. This gives a crisp, scalable X with zero dependencies — no SVG, no icon font, no background image. Most of the 18 demos here build the X exactly this way.
Are these CSS close buttons accessible?
Yes. Every demo uses a real button element with an accessible name, visible :focus-visible styling for keyboard users, and aria-hidden on the decorative X glyph. Interactive variants such as Hold to Confirm expose their state, and continuous animations honour the prefers-reduced-motion media query so motion-sensitive users get a calm fallback.
Do these close buttons need JavaScript?
Most don't — 12 of the 18 are pure CSS, using :hover, :active, transitions and pseudo-elements for the whole effect. Six patterns (such as Hold to Confirm, Toast Dismiss and Particle Burst) include a small, self-contained vanilla JS snippet in the JS tab of the code panel for behaviour CSS alone can't do, like a confirm delay or removing the dismissed element.
Where should a close button go on a modal or toast?
Place it in the top-right corner of the dialog or toast, inside the same container, so it is the obvious dismiss control. Keep the hit area at least 24x24px (44x44px is better on touch), give it a clear hover and focus state, and make sure Escape also closes the modal — the button and the Escape key should do the same thing.
Can I use these close buttons in React, Vue or any framework?
Yes. Each demo is plain HTML and CSS (with optional vanilla JS) — no dependencies and no build step. Drop the markup into React (use className), Vue, Svelte, Astro or static HTML and the styles work unchanged. Everything is MIT licensed and free to use commercially.