---
title: "Switch"
description: "An on/off toggle."
---

> Documentation Index
> Fetch the complete documentation index at: https://gistui.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Switch

```gistui
$dark = true
root = Stack(Switch("dark", "Dark mode", bind:$dark), Switch("beta", "Beta features"), $dark ? Tag("Dark is on", tone:info) : Tag("Dark is off"))
```

## Signature

This is the line a model reads in the system prompt.

```gistui
Switch(name, label, bind:$var, checked)
```

- **Group:** Forms
- **Children:** No
- **Positional arguments:** `name`, `label` (a trailing `?` means it may be left out)

## Props

| Prop | Type | How to write it | Notes |
|---|---|---|---|
| `name` | string | positional, required |  |
| `label` | string | positional, required |  |
| `bind` | `$state` variable | `bind:$name` | two-way binding to a $variable |
| `checked` | flag | bare word: `checked` |  |

## Use your own component

Keep the name and schema, swap what is drawn. The prompt and the model's output do not change.

### React

```tsx
import { ui } from "@gistui/react/ui";

const lib = ui.extend({ Switch: MySwitch });
<GistUI library={lib} stream={response.body} />;
```
### Vue

```vue
<GistUI :source="answer" :components="{ Switch: MySwitch }" />
```
### Svelte

```svelte
<GistUI source={answer} components={{ Switch: MySwitch }} />
```
### Solid

```tsx
<GistUI source={answer()} components={{ Switch: MySwitch }} />
```
### Vanilla

```ts
import { ui } from "@gistui/vanilla/ui";

const lib = ui.extend({ Switch: (ctx) => ({ el: myElement(ctx) }) });
```

See [Custom components](/docs/guides/custom-components/) for the full contract. Style hook: `[data-gistui="Switch"]`.

Source: https://gistui.com/docs/components/forms/switch/index.mdx
