Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Field examples · Toggles

Simple Checkbox Field for React

A terms and conditions checkbox with its label beside it.

Framework
UI library

The single agreement checkbox. A horizontal Field puts the Checkbox first and its FieldLabel beside it, in normal weight, so the sentence reads as the choice. Clicking the sentence toggles the box.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

Why is the checkbox beside the sentence?

orientation is horizontal, with the Checkbox first and the FieldLabel beside it. The label reads I agree to the terms and conditions.

Why is the label not bold?

font-normal on FieldLabel keeps the sentence at normal weight. The label is the choice itself.

How does the sentence toggle the checkbox?

FieldLabel names the checkbox, so the sentence is the label for that box. Its htmlFor matches the control's id. max-w-md caps the row.

Does the box start checked?

This checkbox passes no default, so it starts off. Start it checked when the common case is already agreed: pass defaultChecked.

How do I add a longer explanation?

Wrap the FieldLabel and a FieldDescription in FieldContent, and keep the Checkbox as the first child of the horizontal Field.

Which key toggles the checkbox?

Space activates the focused checkbox. Field does not add arrow-key behavior of its own.