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.

Class Name
Type
Description
theme-controllerComponentFor a checkbox or radio button input intended to toggle the page theme.

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.

Here’s an example demonstrating how to save the checkbox state in localStorage: Stackblitz

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.