# Toggle

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

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

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

# Toggle

<iframe className="light-only" src="https://demo.cherry.al/preview/toggle?theme=light" title="Toggle" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />
<iframe className="dark-only" src="https://demo.cherry.al/preview/toggle?theme=dark" title="Toggle" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />

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](/inputs) design page.

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

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

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:

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

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>
