Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Field examples · Layouts

Responsive Layout Field for React

Two fields that stack in a narrow container and sit beside their labels in a wide one.

Framework
UI library

One form for phones and desktops. orientation="responsive" on each Field stacks the label over the input in a narrow container and puts them side by side once the FieldGroup is wide enough. It's a container query, so it follows the form's width, not the screen's.

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 do these labels move beside the inputs?

orientation is responsive on each Field. The label stacks over the input until the FieldGroup container reaches the @md/field-group size, then the label and input share a row.

Why are both fields inside FieldGroup?

The @md switch is a container query on FieldGroup, so responsive fields belong inside that group. This demo wraps Display Name and Username in one FieldGroup capped with max-w-md.

What is in each field?

Each field is a FieldLabel and an Input with type text. The placeholders are John Doe and @johndoe. There is no FieldDescription.

How do the labels connect?

FieldLabel names that input. Its htmlFor matches the control's id. The labels are Display Name and Username.

Where would a hint go on the wide row?

Put the label and a FieldDescription in FieldContent, as the first child of the Field. FieldContent keeps that pair stacked beside the input once the row layout is on.

How do I keep the row at every width?

Set orientation to horizontal instead of responsive. horizontal stays a row, including in a narrow container.