Skip to content
VenusUI
Get started

Floating Label Input

A text field whose label sits inside and floats above on focus or when filled.

Preview

Installation

npx shadcn@latest add @venusui/floating-label-input

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/floating-label-input.tsx

Usage

The code behind the preview above.

floating-label-input-demo.tsx

import { FloatingLabelInput } from "@/components/ui/floating-label-input"

export default function FloatingLabelInputDemo() {
  return (
    <form className="w-full max-w-sm space-y-3">
      <FloatingLabelInput label="Email address" type="email" autoComplete="email" />
      <FloatingLabelInput label="Company" autoComplete="organization" />
    </form>
  )
}

API reference

PropTypeDefaultDescription
labelstring—Visible label. Required.
classNamestring—Classes for the wrapper.

All <input> props except placeholder, which the floating effect uses internally.

Requirements

  • Tailwind CSS v4, with a cn helper at @/lib/utils. CSS only; works in Server Components.

Customization

  • Mark errors with aria-invalid; the border turns red. Link an error message with aria-describedby.
  • Pass id to connect it to your own error text; otherwise an id is generated.

Accessibility

  • Uses a real <label> linked to the input, so it is announced and clicking it focuses the field.
  • The label never disappears, unlike a placeholder-only field.

Troubleshooting

The label overlaps the text.
Don’t pass a placeholder. The component relies on an empty placeholder to know when the field is empty.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A number field with minus and plus buttons, clamped to a range.

Loading preview

OTP Input

Inputs

One-time code entry in separate boxes with paste, autofill and keyboard navigation.

Loading preview

A lock-screen passcode keypad that shakes on a wrong code and unlocks on the right one.