Skip to content

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

Free

Fieldset with Legend for React

Address Information, the note We need your address to deliver your order, then Street Address with City beside Postal Code.

Address Information is the caption. Under it: We need your address to deliver your order. Street Address is its own row, placeholder 123 Main St. City and Postal Code share the next row, New York and 90502.

Put it on a few related inputs that need one name. A frame with no legend is a Card. Base UI in React does not check the postal code.

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.
Use email insteadNo credit card

Anatomy

Field anatomy: root, label, input, description, error

Usage

<FieldSet className="w-full max-w-md">
  <FieldLegend>Address Information</FieldLegend>
  <FieldDescription>
    We need your address to deliver your order.
  </FieldDescription>
  <FieldGroup>
    <Field>
      <FieldLabel htmlFor="address-street-address">Street Address</FieldLabel>
      <Input
        id="address-street-address"
        placeholder="123 Main St"
        type="text"
      />
    </Field>
    <div className="grid grid-cols-2 gap-4">
      <Field>
        <FieldLabel htmlFor="address-city">City</FieldLabel>
        <Input id="address-city" placeholder="New York" type="text" />
      </Field>
      <Field>
        <FieldLabel htmlFor="address-postal-code">Postal Code</FieldLabel>
        <Input id="address-postal-code" placeholder="90502" type="text" />
      </Field>
    </div>
  </FieldGroup>
</FieldSet>

FAQ

What is the Address Information line?

FieldLegend on FieldSet is the caption. variant is left unset, so it uses the default legend style. The legend is announced with each field's own label.

Where is the delivery sentence?

FieldDescription sits under the legend, on the set: We need your address to deliver your order. The inputs have their own labels under that.

How is the street field laid out?

Street Address is a full-width Field in the FieldGroup. type is text, and the placeholder is 123 Main St.

How do City and Postal Code share a row?

They sit in a grid with grid-cols-2 and gap-4. Placeholders are New York and 90502, and both inputs use type text.

How does each label connect?

FieldLabel names the input. Its htmlFor matches the control's id. The labels are Street Address, City, and Postal Code.

How wide is the address set?

The set is capped with max-w-md. The legend, the description, and the fields share that width.

API Reference

Field

Sets htmlFor="address-street-address", htmlFor="address-city" and htmlFor="address-postal-code". The rest is on the Field page.

Input

Sets id="address-street-address", placeholder="123 Main St", type="text", id="address-city", placeholder="New York" and id="address-postal-code". The rest is on the Input page.