# Toggle: Controlled

> Pass `pressed` and `onPressedChange`. The label stays the same while the icon follows the state.

Example: https://hextaui.com/docs/toggle/examples/controlled
Component docs: https://hextaui.com/docs/toggle.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/toggle-controlled.json
```

This adds `components/examples/toggle/controlled.tsx` with the Toggle component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/toggle/controlled.tsx"
"use client"

import * as React from "react"
import { IconMicrophone, IconMicrophoneOff } from "@tabler/icons-react"

import { Toggle } from "@/components/ui/toggle"

export function ToggleControlled() {
  const [muted, setMuted] = React.useState(false)

  return (
    <div className="flex items-center gap-3 text-sm">
      <Toggle
        variant="outline"
        aria-label="Mute microphone"
        pressed={muted}
        onPressedChange={setMuted}
      >
        {muted ? <IconMicrophoneOff /> : <IconMicrophone />}
      </Toggle>
      <span className="text-muted-foreground">
        Microphone is {muted ? "muted" : "on"}
      </span>
    </div>
  )
}
```

## Props in this example

### Toggle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"default" \| "outline"` | `"default"` |  |
| `pressed` | `boolean` | – |  |
| `onPressedChange` | `(pressed, details) => void` | – |  |

## More Toggle examples

- [Outline](https://hextaui.com/docs/toggle/examples/outline.md)
- [With text](https://hextaui.com/docs/toggle/examples/text.md)
- [Filled when on](https://hextaui.com/docs/toggle/examples/filled-icon.md)
- [Sizes](https://hextaui.com/docs/toggle/examples/sizes.md)
- [Pill](https://hextaui.com/docs/toggle/examples/pill.md)
- [Disabled](https://hextaui.com/docs/toggle/examples/disabled.md)
- [Right to left](https://hextaui.com/docs/toggle/examples/rtl.md)
