Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Checkbox examples · Standard

Horizontal List Checkbox for React

A row of weekday checkboxes that wraps onto a new line when space runs out.

Framework
UI library

Short options waste space stacked one per line. Here five weekdays flow along a row with flex flex-wrap gap-4, each a horizontal Field with its checkbox and label, and they wrap onto a second line when the container is too narrow. The days are a static list mapped to fields. Use it for compact sets with short labels: weekdays, sizes, time slots.

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

When should I use horizontal vs vertical checkbox lists?

Horizontal suits a handful of options with one-word labels, like these five weekdays. Stack the fields in a FieldGroup when the list is longer or the labels wrap inside the row.

How does flex-wrap handle different screen sizes?

The row puts as many days on a line as fit and moves the rest to the next, with no breakpoints. gap-4 keeps the same spacing across and between lines. Each field is w-fit, so it's as wide as its label rather than the full row.

How do I center or right-align horizontal checkbox lists?

Add justify-center or justify-end to the row; every wrapped line aligns the same way. justify-end follows the reading direction, so it puts the days on the left in a right-to-left page.

Should horizontal lists stay horizontal on mobile?

For short labels like these, yes: wrapping handles narrow screens. For longer labels, stack them on small screens with flex-col sm:flex-row. If people mis-tap neighbors, give the row more gap or go vertical.

Can I adjust spacing between horizontal checkboxes?

Change gap-4 to gap-2 or gap-6, or set the two directions apart with gap-x-6 gap-y-2. Tighter rows fit more per line but leave less room between tap targets.

Are horizontal checkbox lists accessible with keyboard?

Yes. Tab moves through the checkboxes in source order, which is the visual order, and Space toggles each. To name the group for screen readers, wrap it in a FieldSet with a FieldLegend such as "Available days".