Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Form examples · Layouts

Vertical Layout (Default) Form for React

A form with labels above their inputs and a description under each, for name, email and phone.

Framework
UI library

Labels above inputs are the default for a reason: they scan quickly and work at any width. Each Field stacks its FieldLabel, Input, FieldDescription and FieldError, and a FieldGroup spaces the three fields evenly in a max-w-md form. A Controller wires each input into React Hook Form and a Zod schema with custom messages checks name, email and phone on submit.

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

How is the vertical stack built?

Field is vertical by default, so each one stacks its FieldLabel, Input, FieldDescription and FieldError. A FieldGroup spaces the three fields and the Submit row.

What does each field validate?

name is z.string().min(2, "Name must be at least 2 characters."), email is z.email("Please enter a valid email address.") and phone is z.string().min(10, "Please enter a valid phone number."). Phone is a length check, not a digit pattern.

Which input types are set?

Email sets type="email" and phone sets type="tel". Name stays a text input. Each FieldLabel points at its input's id, such as form-vertical-layout-default-phone.

What do the descriptions say?

Name says Your full name., email says Your email address. and phone says Your contact number. Each FieldDescription stays visible, and the FieldError appears under it when the field fails.

What is filled in at the start?

defaultValues sets name, email and phone to empty strings. The placeholders are John Doe, john@example.com and +1 (555) 123-4567.

When does Submit check the three fields?

mode is unset, so form.handleSubmit(onSubmit) validates on submit and logs the values only once all three pass.