Floating Label Input

A text field whose label floats up on focus, value and browser autofill.

Category
Forms
Access
Free with an account
Source
160 lines · one file
States
7 drawn

The decision inside it

It notices autofill

A password manager fills a field without an input event, so the label would sit on top of the email. The field listens for the browser's autofill animation and floats the label then.

When to use it

Use Floating Label Input where space is tight and the label can sit inside the field, moving up when it has a value: sign-up, checkout, short forms. Use the plain Input with a Field label for long forms.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Floating Label Input for this.
Install it: npx shadcn@latest add @liro/floating-label-input
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/floating-label-input.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/email-field.tsx
import { FloatingLabelInput } from "@/components/ui/floating-label-input";

export function EmailField({ error }: { error?: string }) {
  return <FloatingLabelInput label="Work email" type="email" name="email" autoComplete="email" error={error} />;
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
labelstring YesThe field's name, inside the box until it floats.
errorstring NoReplaces the hint, marks the field invalid and is announced with it.
hintstring NoOne line under the field.
prefixReact.ReactNode NoBefore the text: a symbol or an icon. Makes the label float from the start.
suffixReact.ReactNode NoAfter the text: a unit, a button or an icon.
variant"outline" | "filled" NoA hairline box or a soft filled well. Default outline.

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themefield

States

All of them are drawn by the component. None is left for you to design.

  • Empty
  • Focused
  • Filled
  • Autofilled
  • Prefix and suffix
  • Error
  • Disabled

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances