Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Textarea examples · Form

Textarea with Error for React

An invalid textarea with a destructive border and an error message under it.

Framework
UI library

Tell people exactly what's wrong, next to the field that's wrong. Here the Field is marked invalid, which gives the Textarea aria-invalid and a destructive border and ring, and a FieldError under it says how to fix the value.

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 should I show textarea validation errors?

After people leave the field or try to submit, not on the first keystroke: an error that appears while someone is still typing reads as a scolding. Once it's shown, clear it as soon as the value becomes valid.

Why use aria-invalid on the textarea element?

It tells screen readers the value is invalid when the field gets focus, and the Textarea's styles read it to turn the border and ring destructive. Base UI's Field passes it only to Base UI controls, and the Textarea is a native textarea, so the demo sets aria-invalid on it too.

What makes a good error message for textareas?

Say what's wrong and how to fix it, as Feedback must be at least 10 characters does. Invalid input or Error leaves people guessing.

Can I use colors other than red for error messages?

The error uses the destructive theme color, so change that token to restyle errors everywhere at once. Keep the message text itself, since color alone doesn't reach everyone.

How do I show multiple validation errors for one textarea?

Show the most important one first, such as empty before too short. If several apply at once, list them all inside the FieldError. FieldError also takes errors, a list of objects with a message such as a form library returns, and renders them as a list.

When should validation errors clear?

As soon as the value is valid, on the change that fixes it, so people see their fix worked. Keep the invalid state in your form's state and pass it to the Field; the demo shows the invalid state only.