> ## Documentation Index
> Fetch the complete documentation index at: https://luau.limerence.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Toggle

> An on / off switch.

Also has everything from [ElementHandle](/ui/classes/element-handle).

An on / off switch. Value is a `boolean`. Saved when created with a non-`nil` key.

|                |                                                    |
| -------------- | -------------------------------------------------- |
| **Value type** | `boolean`                                          |
| **Created by** | [Section:AddToggle](/ui/classes/section#addtoggle) |

## Creation

```luau theme={null}
section:AddToggle(key: string?, label: string, default: boolean?): ToggleHandle
```

***

## SetState

```luau theme={null}
toggle:SetState(value: boolean): ()
```

Same as `SetValue(value)`.

***

## Toggle

```luau theme={null}
toggle:Toggle(): ()
```

Flip the current value and fire `OnChange`.

## Example

```luau theme={null}
local enabled = section:AddToggle("enabled", "Enabled", false)

enabled:OnChange(function(on)
    print("enabled:", on)
end)

enabled:Toggle()
print(enabled:GetValue()) -- flipped
```
