Skip to content

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

Free

Responsive Layout Field for Svelte

Display Name and Username stack their labels in a narrow group and place each label beside the field once the group is wide.

UI library: Ark UI

Display Name and Username, placeholders John Doe and @johndoe. In a narrow group the label sits above the field. Once the group is wide enough, the label sits beside it.

Keep it for one form that should work in a sidebar and on a full page. A label that never moves is a Label. The row follows the group's width, and Ark UI on Svelte does not follow the window.

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

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

Usage

<FieldGroup class="max-w-md"><Field orientation="responsive"><FieldLabel>Display Name</FieldLabel><Input placeholder="John Doe" type="text" /></Field><Field orientation="responsive"><FieldLabel>Username</FieldLabel><Input placeholder="@johndoe" type="text" /></Field></FieldGroup>

FAQ

When do these labels move beside the inputs?

orientation is responsive on each Field. The label stacks over the input until the FieldGroup container reaches the @md/field-group size, then the label and input share a row.

Why are both fields inside FieldGroup?

The @md switch is a container query on FieldGroup, so responsive fields belong inside that group. This demo wraps Display Name and Username in one FieldGroup capped with max-w-md.

What is in each field?

Each field is a FieldLabel and an Input with type text. The placeholders are John Doe and @johndoe. There is no FieldDescription.

How do the labels connect?

FieldLabel names that input. Field connects the two for you, with no ids to write. The labels are Display Name and Username.

Where would a hint go on the wide row?

Put the label and a FieldDescription in FieldContent, as the first child of the Field. FieldContent keeps that pair stacked beside the input once the row layout is on.

How do I keep the row at every width?

Set orientation to horizontal instead of responsive. horizontal stays a row, including in a narrow container.

API Reference

Field

Sets orientation="responsive". The rest is on the Field page.

Input

Sets placeholder="John Doe", type="text" and placeholder="@johndoe". The rest is on the Input page.