Skip to content

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

Free

Textarea with Inline Label for React

A three-row textarea with the label Message beside it, in a horizontal row, instead of stacked above.

The label Message sits beside a textarea, on one row. The field is three rows tall, with the placeholder Type here.

Use it in a settings panel where rows scan faster than a stack. On a narrow screen, put the label above. One line belongs in an Input. In React, Base UI does not switch the layout for you.

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

Textarea anatomy: textarea, caret, placeholder, resize handle

Usage

<Field className="max-w-md" orientation="horizontal">
  <FieldLabel className="w-20" htmlFor="textarea-inline-label">
    Message
  </FieldLabel>
  <Textarea
    className="field-sizing-fixed min-h-0 bg-background"
    id="textarea-inline-label"
    placeholder="Type here..."
    rows={3}
  />
</Field>

FAQ

How do I align the label with a multi-line textarea?

The horizontal Field centers its children, which suits a three-row Textarea. For a taller one, add items-start to the Field so the label lines up with the first line of text.

Why use fixed width w-20 for the inline label?

w-20 gives the label the same width on every row, so a stack of inline fields starts its controls at one edge. Widen it to fit your longest label.

What gap spacing works best for inline label layouts?

The Field's own gap, as here, keeps the label and field visibly apart but paired. Change it with a gap-* class on the Field and use the same value on every row.

When should I use inline labels instead of labels above?

In settings panels and admin forms with many short fields, where rows scan faster than stacks. On narrow screens and for long labels, put the label above; orientation set to responsive switches between the two with the container's width.

Why use min-h-0 on the inline textarea?

The Textarea normally grows with its content from min-h-16. field-sizing-fixed makes it honor rows, and min-h-0 lets it be shorter than the minimum, so it stays three lines tall and the row keeps its alignment.

How many rows should inline textareas have?

Three to five. Fewer, and an Input is the better control; more, and the label floats beside a tall box, so stack the label above instead.

API Reference

Field

Sets orientation="horizontal" and htmlFor="textarea-inline-label". The rest is on the Field page.

Textarea

Sets id="textarea-inline-label", placeholder="Type here..." and rows={3}. The rest is on the Textarea page.