components
Tailwind CSS Theme Controller
If a checkbox or radio input with the theme-controller class is present on the page, the page's theme will be set to the value of that input.
The Theme Controller changes the theme using only CSS. You can use JavaScript to save the input state to the server or localStorage if you want it to persist across page refreshes.
Use the theme-controller
component class with a checkbox input to create a theme switcher that toggles between the default theme and the theme specified in the value.
Create a theme controller using a switch based on the example provided below.
The example below shows how to implement a theme controller using a switch component.
The example below illustrates how to create a theme controller using a switch combined with text.
The example provided shows how to build a theme controller using a switch that features icons.
The example below shows how to build a theme controller using a switch with personalized colors.
Create a theme controller using a radio input based on the example below.
The example below shows how to create a theme controller using a radio button.
Here’s a ready-to-use example of a theme controller utilizing a dropdown menu.
Below are the comprehensively outlined steps you can follow to seamlessly integrate theme-change into your project for efficient theme switching functionality with storing in local storage.
The theme-change
plugin offers three primary attributes to manage themes dynamically:
data-set-theme="luxury"
Use this attribute to set the theme directly for components such as buttons, radio buttons, and dropdowns. The theme is applied upon user interaction (e.g., clicking a button).data-choose-theme
This attribute is designed forselect
components. It dynamically applies the theme based on the selected option from a dropdown menu.data-toggle-theme="soft"
Ideal for toggle components like checkboxes and switches. This attribute allows users to switch between themes interactively by toggling the element.
It also provides the data-act-class="ACTIVECLASS"
attribute, which applies the specified ACTIVECLASS
to the element when it is clicked or toggled.
For a live demonstration and detailed example of using FlyonUI with the theme-change
plugin, check out this StackBlitz example.