Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Textarea examples · Labeled

Textarea with Label for React

A textarea with a visible label above it.

Framework
UI library

The baseline for any form: a Textarea with a visible label. The Field stacks a FieldLabel over the Textarea and ties the two together, so the label names the field for screen readers and a click on it focuses the field.

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 does the FieldLabel link to the Textarea?

The label's for attribute points at the Textarea's id, which gives the field its accessible name and makes clicking the label focus it. Give the Textarea an id and point the FieldLabel at it with htmlFor, as the demo does.

Should the label go above or beside the textarea?

Above, as here, for most forms: a textarea is tall, and a label above reads naturally and fits any width. Put it beside only in dense settings layouts, as the Textarea with Inline Label example does.

What spacing should I use between label and textarea?

The Field sets it, the same gap as every other field, so forms stay consistent. Change it with a gap-* class on the Field if your form needs more or less.

How do I indicate a required textarea field?

Set required so the browser and screen readers know, and add an asterisk to the label for sighted users. The Required Textarea example shows both.

Can placeholder text replace the label?

No. A placeholder disappears once people type and isn't a reliable accessible name. Use it for an example of what to write, alongside the label.

How do I style disabled state for labeled textareas?

Set disabled on the Textarea: it dims to half opacity and stops taking input. Dim the label as well, for example with opacity-50, so the whole field reads as unavailable.