Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input examples · Standard

Input with Label for React

A text input with a label above it.

Framework
UI library

Every field needs a label. This example is the basic pattern: a Field with a FieldLabel reading Name above a text input, linked so that clicking the label focuses the field. Start here and add a description, an error or an icon as the other examples show.

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 field built?

Field stacks its children vertically with a gap: FieldLabel first, then the Input. w-full max-w-sm sets the width.

Why not use only a placeholder?

A placeholder disappears as soon as people type, isn't a reliable accessible name, and is low contrast. Keep the label; use the placeholder, Enter your name, only as a hint.

What type is the input?

text. Set the type that matches the data, such as email, tel or url, to get the right keyboard on phones and the browser's validation.

How do I hide the label visually?

Keep FieldLabel and give it sr-only. The field is still named for screen readers, which a placeholder alone doesn't do.

How do I add a description or an error?

Add FieldDescription or FieldError inside the same Field, as the Helper Text and Error State examples do.