components

Tailwind CSS Swap

Swap enables you to toggle the visibility of two elements using either a checkbox or a class name.

Class Name
Type
Description
swapComponentBase class for swap component.
swap-onComponentIt targets a child element that should be visible when the checkbox is checked or when the swap component is active.
swap-offComponentIt targets a child element that should not be visible when the checkbox is not checked or when the swap component is inactive.
swap-indeterminateComponentIt targets a child element that should be visible when checkbox is indeterminate.
swap-jsComponentIt targets the swap component working with JS instead of checkbox.
swap-flipModifierAdds flip effect to swap content.
swap-rotateModifierAdds rotate effect to swap content.
swap-activeModifierActivates the swap (no need for checkbox).

Utilize the swap component class along with an empty checkbox input and child component classes swap-off and swap-on to create a swap component.

Use below given example for volume/mute swap component.

Apply the modifier class swap-rotate to enable a rotate effect for the swap component.

Use below given example for hamburger button.

Apply the modifier class swap-flip to enable a flip effect for the swap component.

Utilize the component class swap-js to designate a specific swap component for JavaScript functionality, allowing the swap to function without a checkbox. Toggling the modifier class swap-active on a click event of the swap component facilitates this behavior.

Use below given example for RTL swap.

Use below given example for play-pause button.