Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input examples · Standard

Required Field Input for React

A required field with an asterisk in its label and a note explaining it.

Framework
UI library

An asterisk is the common sign for a required field, as long as the form says what it means. This example adds a red asterisk to the Full Name label, marks the input required so the browser checks it, and explains the asterisk in a description under the field. Use it in forms where a few fields must be filled in.

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 asterisk shown?

A span with text-destructive inside FieldLabel. It has aria-hidden, because the input's required state already tells assistive technology the field is required.

Where is required set?

On the Input, the native required attribute.

What does required do when the form is submitted?

The browser blocks the submit while the field is empty and shows its own message. Screen readers announce the field as required.

Why explain the asterisk?

Not everyone knows the convention. The description, * Required field, says it once; in a longer form, put the note at the top.

How do I show my own error message?

Mark the field invalid and put the message in FieldError, as the Error State example does. The field turns destructive and the error shows under the input.

How is Full Name tied to the field?

Clicking the label focuses the field, and screen readers announce it with the field. FieldLabel sets htmlFor to required-full-name, the input's id.