Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Label examples · Standard

Required Label for React

A label with a destructive asterisk that marks the field as required.

Framework
UI library

The familiar asterisk for required fields. The Label says Email and a span with text-destructive holds the *. It's a visual cue only: put required on the control too.

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 marked up?

A span with className="text-destructive" and the character *, after the word Email, inside the Label. There is a space between Email and the span.

Where does the asterisk sit?

On the same line, after the caption. Label is a flex row with gap-2, so the span follows Email.

Where does the red come from?

text-destructive on the span only. The word Email keeps the label's text color. The label itself has no color class.

Does the asterisk mark a field required?

No. The file has no input. The asterisk is visual. Put required on the input as well, or the field is not required to the browser.

How do I point this label at the email input?

Give the input an id and point the label at it. The asterisk span can stay inside the label. Set htmlFor to the input's id.

What will a screen reader say for this label?

Email, then the asterisk, because both are text in the label. The span has no aria-label. The file does not add a legend that explains the mark.