Float label

Float label family from the ai2 styled layer: five decorative floating-label text fields (FloatLabel, ShrinkLabel, InlineFloatLabel, OverlapLabel, SlideLabel) that wrap a real input and animate the label on focus or value. Sizes run from sm to xl, and motion is disabled when the user prefers reduced motion.

componentstyledlabelregistry-item.json
Float label
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://ai2.design/r/tokens.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @ai2/label-float

Requires @ai2 in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { FloatLabel } from "@/components/ui/label-float"export function Example() {  return <FloatLabel placeholder="Email" />}
  • Use a single-line text field where the label should sit in the empty field and rise on focus or input, saving vertical space compared with a label above the field.
  • Pick ShrinkLabel or InlineFloatLabel when the label must stay inside the box, and FloatLabel, OverlapLabel, or SlideLabel when it may sit outside or on the border.
  • Use it in forms that follow the ai2 token system, where colors must come from tokens rather than hard-coded values.
  • Avoid it where the label must always be visible or where the field needs several lines, since it is a single-line text input with no description or error slot.

Examples

Default floating label

FloatLabel with the default md size and the default placeholder "Email" used as label text.

default-floating-label.tsx
import { FloatLabel } from "@/components/ui/label-float"export function EmailField() {  return <FloatLabel />}

Shrink label with a large size and custom text

ShrinkLabel keeps the label inside the taller lg box. The children prop replaces the placeholder as the label text.

shrink-label-with-a-large-size-and-custom-text.tsx
import { ShrinkLabel } from "@/components/ui/label-float"export function NameField() {  return (    <ShrinkLabel size="lg" placeholder="Name">      Full name    </ShrinkLabel>  )}

Overlap label on the border

OverlapLabel places the label on the top border with a background chip, at the small size.

overlap-label-on-the-border.tsx
import { OverlapLabel } from "@/components/ui/label-float"export function SearchField() {  return <OverlapLabel size="sm" placeholder="Search" className="w-72" />}

Slide label in a form

SlideLabel with the xl size inside a simple form stack, with the className prop passed through to the root span.

slide-label-in-a-form.tsx
import { SlideLabel } from "@/components/ui/label-float"export function PasswordForm() {  return (    <form className="flex flex-col gap-4">      <SlideLabel size="xl" placeholder="Password" />    </form>  )}

API reference

PropTypeDefaultDescription
classNamestring—Extra classes merged with cn() onto the outer span (data-slot="styled-label"). Use it to set width or spacing.
size"sm" | "md" | "lg" | "xl""md"Sets the box height, label and input text size, and label offsets. The outer box uses h-9 to h-12 for FloatLabel, OverlapLabel, and SlideLabel. The inner box uses h-11 to h-16 for ShrinkLabel and InlineFloatLabel.
childrenReact.ReactNode—Label content. When omitted, the placeholder value is rendered as the label text.
placeholderstring"Email"Fallback label text, used when children is not given. It is also set as the input placeholder, but the placeholder is transparent, so the label is the visible hint. Applies to all five exports; FloatProps has no default of its own, and each component supplies "Email".

Accessibility

  • The label is a real <label> element linked to the input with htmlFor, using an id from React.useId(), so the input gets an accessible name from the label text.
  • The label has pointer-events-none, so clicks pass through to the input and focus still moves to it.
  • The input placeholder is transparent (placeholder:text-transparent), so the visible label is the only hint and the placeholder is not shown as a second hint.
  • The label changes color to text-info when active. Do not rely on color alone to show that the field has a value; the input text itself is the value indicator.
  • Focus is shown with a focus-visible ring (3px ring-ring/50), so keyboard users can see where focus is.
  • Motion respects prefers-reduced-motion: useReducedMotion() switches the transition to duration 0.
  • The component exposes no name, id, required, disabled, or aria-invalid props. Pass the field's validation state through a wrapper or extend the source to add them.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Float label" component (ai2/label-float) from its shadcn registry.1. Install it with: npx shadcn@latest add @ai2/label-float2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: className, size, children, placeholder.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { FloatLabel } from "@/components/ui/label-float"export function Example() {  return <FloatLabel placeholder="Email" />}```

Files & dependencies

  • registry/ai2/styled/label-float.tsx→ components/ui/label-float.tsx
dependenciesmotion@^12.42.2
registryDependencies@ai2/tokens

Looks similar, elsewhere