Swap Component
A smooth, zero-JavaScript swap component built with native HTML inputs and Tailwind CSS. Toggle between two content states with fade, rotate, and flip animations. Perfect for theme toggles, mode switches, loading states, and icon transitions for interactive, accessible UI elements.
Swap components toggle between two content states with smooth animations in response to user interaction. Built with semantic HTML and CSS transitions, swaps enable elegant state changes without JavaScript. The Frutjam swap system supports multiple animation stylesβideal for theme toggles, mode switches, loading states, and interactive illustrations.
| Class | Type | Description |
|---|---|---|
| swap | Base | Checkbox-driven two-state toggle wrapper |
| swap-rotate | Style | Rotates between states |
| swap-flip | Style | Flips between states with a 3D effect |
Basic Usage
Create a simple swap with emoji or text content using a checkbox to toggle states.
1 2 3 4 5 | <label class="swap"> <input type="checkbox" /> <div class="swap-on">βοΈ</div> <div class="swap-off">π</div> </label> |
1 2 3 4 5 | <label className="swap"> <input type="checkbox" /> <div className="swap-on">βοΈ</div> <div className="swap-off">π</div> </label> |
Swap Animations
Apply different animation styles for visual transitions: fade (default), rotate, and flip.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <label class="swap"> <input type="checkbox" /> <div class="swap-on">Online</div> <div class="swap-off">Offline</div> </label> <label class="swap swap-rotate"> <input type="checkbox" /> <div class="swap-on">β</div> <div class="swap-off">βοΈ</div> </label> <label class="swap swap-flip"> <input type="checkbox" /> <div class="swap-on">Yes</div> <div class="swap-off">No</div> </label> |
Swap with SVG Icons
Use SVG icons for visual state changes with smooth animations.
1 2 3 4 5 6 7 8 9 | <label class="swap swap-rotate"> <input type="checkbox" /> <svg class="swap-on" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <circle cx="12" cy="12" r="1"/><path d="M12 2v6m0 4v6M4.22 4.22l4.24 4.24m2.98 2.98l4.24 4.24M2 12h6m4 0h6M4.22 19.78l4.24-4.24m2.98-2.98l4.24-4.24"/> </svg> <svg class="swap-off" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/> </svg> </label> |
Swap as Button
Combine swap functionality with button component styling for interactive toggles.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <label class="btn btn-primary swap"> <input type="checkbox" /> <div class="swap-on">Light Mode</div> <div class="swap-off">Dark Mode</div> </label> <label class="btn btn-secondary swap swap-flip"> <input type="checkbox" /> <div class="swap-on">Connected</div> <div class="swap-off">Disconnected</div> </label> <label class="btn btn-outline swap swap-rotate"> <input type="checkbox" /> <div class="swap-on">Expanded</div> <div class="swap-off">Collapsed</div> </label> |
Swap as Badge
Create compact toggle badges for status or category switching.
1 2 3 4 5 6 7 8 9 10 11 | <label class="badge badge-primary swap cursor-pointer"> <input type="checkbox" /> <div class="swap-on">Active</div> <div class="swap-off">Inactive</div> </label> <label class="badge badge-success swap cursor-pointer swap-flip"> <input type="checkbox" /> <div class="swap-on">β Verified</div> <div class="swap-off">Pending</div> </label> |
Combined Swap Variants
Mix different animation styles and content types for complex toggle scenarios.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <label class="swap swap-flip"> <input type="checkbox" /> <div class="swap-on">β</div> <div class="swap-off">β</div> </label> <label class="swap swap-rotate"> <input type="checkbox" /> <div class="swap-on">Saving...</div> <div class="swap-off">Save</div> </label> <label class="btn btn-ghost btn-sm swap swap-flip"> <input type="checkbox" /> <div class="swap-on">Show Less</div> <div class="swap-off">Show More</div> </label> |