Tailwind CSS Switch - React

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.


import { Switch } from "@material-tailwind/react";
 
export default function Example() {
  return <Switch defaultChecked />;
}

Switch Colors

The Switch component comes with 19 different colors that you can change it using the color prop, below there are some examples of the colors but you can check all of the them here.

import { Switch } from "@material-tailwind/react";
 
export default function Colors() {
  return (
    <div className="flex w-max gap-4">
      <Switch color="blue" defaultChecked />
      <Switch color="red" defaultChecked />
      <Switch color="green" defaultChecked />
      <Switch color="amber" defaultChecked />
      <Switch color="teal" defaultChecked />
      <Switch color="indigo" defaultChecked />
      <Switch color="purple" defaultChecked />
      <Switch color="pink" defaultChecked />
    </div>
  );
}

Switch with Label

You can add a label for the Switch component by passing the label prop to the Switch component.

import { Switch } from "@material-tailwind/react";
 
export default function Example() {
  return <Switch id="auto-update" label="Automatic Update" />;
}

Switch Ripple Effect

You can turn on/off the ripple effect for the Switch component using the ripple prop.

import { Fragment } from "react";
import { Switch } from "@material-tailwind/react";
 
export default function Example() {
  return (
    <Fragment>
      <Switch id="ripple-on" label="Ripple Effect On" ripple={true} />
      <Switch id="ripple-off" label="Ripple Effect Off" ripple={false} />
    </Fragment>
  );
}
Edit this page on Github