Switch

The Switch component is used as an alternative for the checkbox component.

SourceTheme Source

The Switch component is used as an alternative for the Checkbox component. You can switch between enabled or disabled states.

Import#

import { Switch } from '@chakra-ui/react'

Usage#

<Field.Root>
<HStack>
<Field.Label htmlFor='email-alerts' mb='0'>
Enable email alerts?
</Field.Label>
<Switch.Root id='email-alerts'>
<Switch.Track>
<Switch.Thumb />
</Switch.Track>
</Switch.Root>
</HStack>
</Field.Root>

Changing the size#

Pass the size prop to change the size of the Switch.

<HStack>
<For each={['sm', 'md', 'lg']}>
{(size) => (
<Switch.Root size={size} key={size}>
<Switch.Track>
<Switch.Thumb />
</Switch.Track>
</Switch.Root>
)}
</For>
</HStack>

Changing the color palette#

Set the colorPalette prop to change the color of the Switch.

<Switch.Root defaultChecked colorPalette='teal'>
<Switch.Track>
<Switch.Thumb />
</Switch.Track>
</Switch.Root>
Edit this page on GitHub

Proudly made inNigeria by Segun Adebayo

Deployed by â–² Vercel