StealThis .dev

Swap

DaisyUI-style swap component — toggle between two states (icon/text) with flip, rotate, or fade animations. CSS-only, no JavaScript.

Open in Lab
css
Targets: HTML

Code

Swap

A CSS-only toggle component inspired by DaisyUI’s swap pattern. Uses a hidden <input type="checkbox"> to drive state, with no JavaScript required. Three animation variants — flip, rotate, and fade — cover the most common use cases.

How it works

The .swap wrapper contains a hidden checkbox and two child elements: .swap-on (shown when checked) and .swap-off (shown when unchecked). CSS :checked selectors and sibling combinators handle the entire transition.

Variants

ModifierEffect
.swap-flip3D Y-axis flip between states
.swap-rotate180° rotation crossfade
.swap-fadeSimple opacity crossfade

Demos

  1. Sun / Moon — theme toggle with rotate animation
  2. Play / Pause — media control with fade animation
  3. Menu / Close — hamburger icon with rotate animation
  4. Star — filled/outline toggle with flip animation

When to use it

  • Dark/light mode toggles
  • Media player controls
  • Mobile navigation hamburger menus
  • Favorite/like buttons