shadcn.io is an independent project built on shadcn/ui
A bordered list has two rows. Marketing emails is off, with Receive emails about new products. Security emails is on, with Receive emails about account security.
Use a divided list for related settings without a card around each one. One featured setting can stand alone in a card. Choices that wait for Save fit a Checkbox. In React, Base UI keeps each switch's own state.
Installation
Anatomy

Usage
<div className="flex flex-col divide-y rounded-lg border bg-background">
<Field className="p-4" orientation="horizontal">
<FieldContent>
<FieldLabel
className="font-medium"
htmlFor="switch-settings-list-marketing"
>
Marketing emails
</FieldLabel>
<FieldDescription>Receive emails about new products</FieldDescription>
</FieldContent>
<Switch id="switch-settings-list-marketing" />
</Field>
<Field className="p-4" orientation="horizontal">
<FieldContent>
<FieldLabel
className="font-medium"
htmlFor="switch-settings-list-security"
>
Security emails
</FieldLabel>
<FieldDescription>
Receive emails about account security
</FieldDescription>
</FieldContent>
<Switch defaultChecked id="switch-settings-list-security" />
</Field>
</div>FAQ
How are the two settings stacked?
The wrapper is flex flex-col divide-y rounded-lg border bg-background. Each row is a horizontal Field with p-4, holding a FieldContent and a Switch.
Which switch starts on?
Marketing emails starts off. Security emails starts on through its default prop.
The prop is defaultChecked.
How is each label tied to its switch?
Each row is its own Field, so each label belongs to its own switch.
The Switch has an id, and the FieldLabel points at it with htmlFor.
How do I control this switch in React?
Each switch keeps its own state here. To control them, keep each switch's on or off state in your own state, such as one object with a key per setting, and pass it back.
Pass checked; onCheckedChange receives the new boolean.
API Reference
Field
Sets orientation="horizontal", htmlFor="switch-settings-list-marketing" and htmlFor="switch-settings-list-security". The rest is on the Field page.
Switch
Sets id="switch-settings-list-marketing", defaultChecked and id="switch-settings-list-security". The rest is on the Switch page.



