Use our Tailwind CSS Switch component to let users adjust settings on/off. The option that the Switch controls, as well as the state it's in, should be made clear from the corresponding inline label.
See below our example that will help you create simple and easy-to-use Switch component for your Tailwind CSS and React project.
Here's how to implement a Switch component. It can be used for forms or other components.
You can use the defaultChecked prop for making the Switch component checked by default.
We provide different colors for Switch component like primary, secondary, info, success, warning, and error so you can adapt it easily to your needs. You can simply use the color prop to change the Switch component color.
In the example below, we've showcased the different colors for Switch component that you can use in your project.
The Switch component can be used with a label to provide more context to the user. In the example below, we've added a label by using the Switch and Typography components together.
You can disable the Switch component by adding the disabled prop. This will prevent the user from interacting with the Switch component.
Use the example below to create a Switch component with a link to the terms and conditions inside it's label.
Use the example below to create a Switch component with a title and description as it's label to provide more information about the Switch component action.
You can use className prop to customize the Switch component style. In the example below, we make a Switch component similar to IOS switch component.