shadcn.io is not affiliated with official shadcn/ui
Form examples · Layouts
Compact Form for React
A compact sign-in form with tight spacing, shorter inputs and a full-width Sign In button.
Space-constrained places need compact forms: sign-in popovers, sidebars and small dialogs where every pixel counts. Two fields, username and password, sit in a FieldGroup with gap-3 instead of the default gap, each Field tightened to gap-1.5, with h-9 inputs, text-xs errors and a full-width Sign In button inside a max-w-sm form. A Controller wires each input into React Hook Form and a Zod schema checks them on submit.
Preview
Installation
FAQ
What makes this form compact?
The FieldGroup is gap-3 and each Field is gap-1.5, so label, input and error sit close together. Both inputs are h-9, both FieldErrors are text-xs, and the form is max-w-sm.
What do username and password have to satisfy?
username is z.string().min(2) and password is z.string().min(8). Neither passes a custom message, so FieldError shows Zod's default text, such as Too small: expected string to have >=2 characters.
How is the password field different from username?
Its Input sets type="password" and the placeholder ********. Username is a text input with the placeholder johndoe. Both spread the Controller's field. Each FieldLabel points at its input with htmlFor, such as compact-form-password.
How is Sign In sized?
Sign In is a type="submit" button with h-9 w-full, so it matches the input height and spans the column.
Related
- Inline FormAn inline newsletter form with an email
- Login FormA login form with a welcome heading
- Vertical Layout (Default) FormA form with labels above their inputs and
- Horizontal Layout FormA form with each label beside its input
- Input with LabelA text input with a label above it
- Standard DialogA share dialog with a read-only link, a