Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Label with Optional Indicator for Solid

The label Phone Number with a muted (optional) on the same line, for a field that is not required.

UI library: Ark UI

Phone Number is the label. On the same line, muted text reads (optional).

Mark the optional fields when almost every field is required. A destructive asterisk on a Field label is the other convention. Ark UI in Solid does not know which fields are optional.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Label anatomy: label, control, text

Usage

<Label>
    Phone Number
    <span class="font-normal text-muted-foreground">(optional)</span>
  </Label>

FAQ

How is the optional marker written?

As the text (optional) inside the label, after Phone Number. The span is font-normal text-muted-foreground.

Why does the marker look quieter than the caption?

Label is font-medium. The span sets font-normal and text-muted-foreground, so the word optional drops the weight and uses the muted color.

What puts (optional) on the same line?

Label is a flex row with gap-2. The span is a child, so it follows Phone Number. The file adds no margin class.

Does (optional) change validation?

No. There is no input in the file. The marker is text. Leave required off the control when that field can be empty.

Will a screen reader say optional?

Yes. The word is text inside the label, so it is part of the caption. The demo does not set an aria-label that would replace it.

How do I point this label at the phone input?

Give the input an id and point the label at it. The (optional) span can stay inside the label, where it is now. Set for to the input's id.

API Reference

Label

No extra props in this demo. The rest is on the Label page.