shadcn.io is not affiliated with official shadcn/ui
Checkbox examples · Standard
Right-Aligned Checkbox for React
A list of notification settings with each label at the start of its row and the checkbox at the end.
Labels first, boxes at the end: the layout of a settings screen. Each row is a horizontal Field with the FieldLabel before the Checkbox; the label stretches to fill the row, which pushes the box to the end edge so the three boxes line up in a column. The ends follow the reading direction, so a right-to-left page mirrors it. Use it for notification channels, privacy options and other lists of independent on/off settings.
Preview
Installation
FAQ
When should I use right-aligned checkboxes?
For settings, where each row is an option people turn on or off and they scan the labels first. This demo puts FieldLabel before the checkbox, and the label grows so the box sits at the end of the row.
Should I use right-aligned checkboxes or toggle switches?
It depends on when the change applies. Use checkboxes when the settings are saved with a button. Use a Switch when each one takes effect immediately. The same row, label then control, works for both.
How do the checkboxes line up with different label lengths?
The label grows to fill whatever the box doesn't use, so every box sits at the end edge whatever the label's length, and they form one column. The list is capped at max-w-xs here; very long labels wrap inside their own space.
Do right-aligned checkboxes work well on mobile?
Yes. The stretched label is clickable, so tapping anywhere along the row's text toggles the box, not just the box itself. On touch screens, give rows more height (a larger gap-*, or padding on each Field) so neighbors are hard to hit by mistake.
Related
- Vertical List CheckboxA stacked list of programming language
- With Description CheckboxA checkbox with a label and a line of
- Horizontal List CheckboxA row of weekday checkboxes that wraps
- Settings List SwitchTwo settings rows, each with a label, a
- Default ToggleAn icon-only toggle that turns bold on
- Nested List CheckboxA select-all checkbox over three indented