Close Button

Close Button

A “close” icon created in pure CSS from two pseudo-elements. On hover, both lines forming the cross smoothly rotate 180 degrees using transform: rotate(180deg) and transition.

See the Pen Close Button.

Pure CSS Close Buttons

Pure CSS Close Buttons

A collection of “close” icon variations created with a single base class, .close, and multiple modifier classes. Each modifier changes one property to create a new style.

See the Pen Pure CSS Close Buttons.

Back To Close

Back To Close

Creation of a complex icon from three <span> elements that form a “back” arrow in one state and reconfigure into a cross in another state with the .open class. JavaScript is used solely for toggling the state.

See the Pen Back To Close.

Close Button

Close Button

A minimalist pure CSS button featuring a creative line-to-border transformation animation on hover. This lightweight snippet leverages pseudo-elements and hardware-accelerated transform properties, providing a smooth text reveal and high-performance UI micro-interaction.

See the Pen Close Button.

Open / Close

Open / Close

A seamless icon morphing animation that transforms a directional arrow into a close button upon click. This lightweight snippet utilizes CSS pseudo-elements and hardware-accelerated transitions to create a responsive toggle control for dropdowns and menus.

See the Pen Open / Close.

Animated Close Icon

Animated Close Icon

A minimalist pure CSS close button featuring a smooth rotation and color shift animation on hover. This snippet utilizes CSS transitions to trigger a label reveal and transform the cross icon, offering a lightweight and intuitive UI micro-interaction for modals or popups.

See the Pen Animated Close Icon.

Interactive Close Button

Interactive Close Button

A stylish interactive close button built with SCSS, featuring a unique internal sliding animation triggered on hover. This snippet utilizes custom cubic-bezier transitions and color shifting to create a fluid and engaging UI micro-interaction for modals or menus.

See the Pen Interactive Close Button.

Open / Close Button Animation

Open / Close Button Animation

A sleek hamburger menu toggle that morphs into a close icon using synchronized CSS @keyframes animations. This snippet features a satisfying color-fill hover effect and precise transformations, making it a perfect UI component for responsive navigation systems.

See the Pen Open / Close Button Animation.

Close Animation

Close Animation

Animated Close button implemented with SCSS using pseudo-elements and CSS transforms. This lightweight UI component features a smooth cross-line transition effect on hover, making it perfect for modals and pop-ups in modern web apps.

See the Pen Close Animation.

Chat Bubble Button

An interactive, zero-JS chat icon morphs into a close button on click. By nesting two svg paths and shifting their stroke-dashoffset parameters dynamically, the outline of the rounded speech bubble “unravels” to form a sharp, rotated “X” symbol. Simultaneously, the three internal dot circles scale down to zero.

See the Pen Chat Bubble Button.

Pure CSS Close Button

An elegant, splitting close crossmark is created inside this square button on hover. The :before and :after pseudo-elements are angled at 45deg. At rest, their zero-width borders touch. Hovering transitions width to 15px, sliding the solid segments outward to create a gap and split the “X” into four separate corner marks.

See the Pen Pure CSS Close Button.

Frequently Asked Questions

What is the best way to create an X-shaped close button using only CSS?

Use ::before and ::after pseudo-elements with transform: rotate(45deg) and rotate(-45deg) to form the two crossing lines. Set width and height on the pseudo-elements with position: absolute centering — no Unicode characters or SVG needed.

How do I ensure the close button is accessible for keyboard users?

Always use a native <button> element with aria-label='Close' for screen readers. The <button> provides inherent keyboard focusability and Enter/Space activation without additional JavaScript event binding.

How can I animate the close button rotation on hover without layout thrash?

Animate transform: rotate(90deg) on the entire button or its pseudo-elements using CSS transitions. Since transform is a compositor-only property, the rotation stays on the GPU thread and does not trigger repaints or layout recalculations.

How do I make close buttons responsive to different container sizes?

Set the button width, height, and pseudo-element thickness using clamp() with relative units. For a modal-relative close button, use Container Query units to scale the button proportionally to its parent container.