Back to elements
ElementForm & InputFree

Floating Label Input React component

A text field whose label sits inside it and floats up on focus or once filled, in outlined (label in a notch in the border), filled or underline styles, with an optional icon, clear button, validity tick, character count, helper text and a shake on error.

When to use the Floating Label Input component

Use Floating Label Input in compact forms (sign-up, checkout, settings) where a label above every field takes too much room but a placeholder alone would disappear once people type.

Set surface to the background behind outlined fields so the label's notch blends in.

Installation

Add the Floating Label Input component to your project with the shadcn CLI. It lands in components/floating-label-input.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/floating-label-input.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<FloatingLabelInput /> accepts 15 props (required ones are marked *).

  • label*
    string
  • value
    string
  • defaultValue
    string
    Default: ""
  • onValueChange
    (value: string) => void
  • variant

    outlined: label sits in a notch in the border. filled: shaded field. underline: a line that grows on focus.

    "outlined" | "filled" | "underline"
    Default: "outlined"
  • helperText
    string
  • error
    string
  • valid

    Shows a green tick (e.g. after validation passes).

    boolean
    Default: false
  • icon
    React.ReactNode
  • clearable
    boolean
    Default: false
  • showCount

    Show "12 / 40" when maxLength is set.

    boolean
    Default: false
  • size
    "sm" | "md" | "lg"
    Default: "md"
Show all 15 props
  • surface

    Background behind the field, used to cut the outlined notch.

    string
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

Is the label still a real label?
Yes. It's a <label> tied to the input, so clicking it focuses the field and screen readers announce it; it only moves visually.
What's the surface prop for?
In the outlined style the floating label cuts the border with a background patch; surface is that colour, and should match what's behind the field.
How are errors shown?
The border and label turn coral, the field shakes once and the message replaces the helper text, linked to the input for assistive tech.

Related components

Input Group
Free
Content Switch
Free
Masked Input
Free
Variant Swatches
Free
Knob
Free
Blockquote
Free