# Toggle

> Cherry Toggle component - a stylish checkbox/radio alternative with validation states.

Source: https://docs.cherry.al/v1/code/toggle

> For the complete documentation index, see [llms.txt](https://docs.cherry.al/llms.txt).

# Toggle

<Preview bleed>
<iframe className="light-only" src="https://v1.cherry.al/preview/toggle?theme=light" title="Toggle" loading="lazy" style={{ width: "100%", height: "320px" }} />
<iframe className="dark-only" src="https://v1.cherry.al/preview/toggle?theme=dark" title="Toggle" loading="lazy" style={{ width: "100%", height: "320px" }} />

```jsx
import React from "react";
import { Toggle } from "cherry-styled-components";

export default function Page() {
  return <Toggle defaultChecked />;
}
```
</Preview>

The Toggle component is a stylish input checkbox or radio element.

Keep in mind that the `<input>` element inherently includes native browser properties like `onChange`. Cherry UI components introduce custom properties that always begin with a `$` to distinguish them from native props.

For design guidelines and all interactive states, see the [Inputs](/v1/inputs) design page.

With a label. Pass an `id` so the label is associated with the input; without it, clicking the label won't toggle the switch:

```html
<Toggle id="newsletter" $label="Label" $fullWidth />
```

With success and error states:

```html
<Toggle $success />
<Toggle $error />
```

Disabled toggles get built-in styling with a `not-allowed` cursor and gray colors. A toggle that is disabled and checked (a locked-on switch, such as a "Necessary cookies, always on" row) is grayed out the same way, and so is a toggle inside a disabled `<fieldset>`:

```html
<Toggle disabled />
<Toggle disabled defaultChecked />
```

The underlying input always renders with `role="switch"`, so assistive technologies announce it as a switch.

## Properties

<Field value="type" type='"checkbox" | "radio"'>
  The underlying input type. Defaults to `"checkbox"`.
</Field>

<Field value="$label" type="string">
  Label text displayed alongside the toggle. Requires an `id` on the toggle so the label's `htmlFor` points to the input; otherwise label clicks won't toggle it.
</Field>

<Field value="$size" type='"default" | "big" | "small"'>
  Size of the toggle.
</Field>

<Field value="$error" type="boolean">
  Shows error state styling.
</Field>

<Field value="$success" type="boolean">
  Shows success state styling.
</Field>

<Field value="$fullWidth" type="boolean">
  Makes the toggle span the full width of its container.
</Field>

<Field value="$wrapperClassName" type="string">
  Class name applied to the wrapper element around the toggle, for restyling from the outside.
</Field>

<Button href="https://github.com/cherry-design-system/styled-components/blob/main/src/lib/toggle.tsx" icon="code" iconPosition="left">
  View Source
</Button>
