Switch
A toggle between two states
Switch exposes a controlled or uncontrolled boolean state through accessible, independently styled frame and thumb parts.
Features
Accessible, composable, and customizable
Independent frame and thumb styling and animation
Sizing with controlled or uncontrolled state
Native mobile Switch through the native prop
Installation
Switch is already installed in tamagui, or you can install it independently:
yarn
npm
bun
pnpm
Usage
Headless usage
To use the headless switch without @tamagui/core, install @tamagui/switch-headless:
yarn
npm
bun
pnpm
The useSwitch hook provides all the state and accessibility props needed to build a custom switch with any styling solution:
API reference
Switch
Switch extends View, inheriting all the
Tamagui standard props. Sizes come from the shared
Sizing ladder.
Props
size
'xs' | 'sm' | 'md' | 'lg' | 'xl'
A named size ("xs" to "xl", default "md") is a rung in the sizing ladder: the track is the ladder's square stretched 1.9 wide, and the thumb insets 2px on every side.
labeledBy
string
Set aria-labeled-by.
name
string
Equivalent to input name.
value
string
Give it a value (for use in HTML forms).
checked
boolean
Control the input.
defaultChecked
boolean
Uncontrolled default value.
required
boolean
Sets aria-required.
onCheckedChange
(checked: boolean) => void
Callback called when checked state changes.
unstyled
boolean
Default:
falseWhen true, removes all default Tamagui styling.
native
NativeValue<"mobile" | "ios" | "android">
Render to a native switch. (Not supported on web)
nativeProps
SwitchProps (from `react-native`)
Props to pass to the native Switch.
activeStyle
ViewStyle
Styles to apply when the switch is checked/active.
activeTheme
string | null
Theme to apply when the switch is checked/active.
Switch.Thumb
Switch.Thumb extends View inheriting all the
Tamagui standard props, plus:
Props
unstyled
boolean
Default:
falseWhen true, removes all default Tamagui styling.
activeStyle
ViewStyle
Styles to apply to the thumb when the switch is checked/active.
useSwitch
The useSwitch hook accepts three arguments:
Props (first argument)
Props
labeledBy
string
Set aria-labelledby for accessibility.
disabled
boolean
Whether the switch is disabled.
name
string
Form input name for the hidden input.
value
string
Form input value.
required
boolean
Whether the switch is required in a form.
onPress
(event) => void
Called when switch is pressed (composed with internal handler).
State (second argument)
A tuple of [checked, setChecked] where:
checked: Current boolean statesetChecked: React state setter function
Return value
| Property | Type | Description |
|---|---|---|
switchProps | object | Props to spread on your switch element (role, aria-checked, onPress, etc.) |
switchRef | Ref | Composed ref to attach to your switch element |
bubbleInput | ReactNode | null | Hidden input for form compatibility (render as sibling, web only) |
- Property
switchProps- Type
object- Description
- Props to spread on your switch element (role, aria-checked, onPress, etc.)
- Property
switchRef- Type
Ref- Description
- Composed ref to attach to your switch element
- Property
bubbleInput- Type
ReactNode | null- Description
- Hidden input for form compatibility (render as sibling, web only)
Source
v2-look Switch: token-based frame and thumb sizing with theme background and focus styling, over the unstyled @tamagui/ui Switch behavior. This is the exact source the registry ships — copy it into your app and the examples above import from your copy.
components/tamagui/Switch.tsxDependencies
yarn add @tamagui/core @tamagui/switchExpects theme tokens: background, outline-color.
Need raw behavior without any skin? tamagui/unstyled re-exports the @tamagui/ui primitives (advanced).