Tailwind CSS Floating Label - Flowbite

Use the floating label style for the input field elements to replicate the Material UI design system from Google and choose from multiple styles and sizes

Table of Contents#

Floating label example#

Get started with the following three styles for the floating label component and use the label tag as a visual placeholder using the peer-placeholder-shown and peer-focus utility classes from Tailwind CSS.

Edit on GitHub

  • React TypeScript
'use client';

import { FloatingLabel } from 'flowbite-react';

export default function FloatingLabel() {
  return (
    <>
      <FloatingLabel
        buttonStyle="filled"
        label="Label"
      />
      <FloatingLabel
        buttonStyle="outlined"
        label="Label"
      />
      <FloatingLabel
        buttonStyle="standard"
        label="Label"
      />
    </>
  )
}


Disabled state#

Apply the disabled attribute to the input fields to disallow the user from changing the content.

Edit on GitHub

  • React TypeScript
'use client';

import { FloatingLabel } from 'flowbite-react';

export default function FloatingLabel() {
  return (
    <>
      <FloatingLabel
        buttonStyle="filled"
        disabled
        label="Label"
      />
      <FloatingLabel
        buttonStyle="outlined"
        disabled
        label="Label"
      />
      <FloatingLabel
        buttonStyle="standard"
        disabled
        label="Label"
      />
    </>
  )
}


Validation#

Use the following examples of input validation for the success and error messages by applying the validation text below the input field and using the green or red color classes from Tailwind CSS.

Edit on GitHub

  • React TypeScript
'use client';

import { div } from 'flowbite-react';

export default function FloatingLabel() {
  return (
    <>
      <div className="grid grid-flow-col justify-stretch space-x-4">
        <FloatingLabel
          buttonStyle="filled"
          label="Filled Success"
        />
        <FloatingLabel
          buttonStyle="outlined"
          label="Outlined Success"
        />
        <FloatingLabel
          buttonStyle="standard"
          label="Standard Success"
        />
      </div>
      <div className="grid grid-flow-col justify-stretch space-x-4">
        <FloatingLabel
          buttonStyle="filled"
          error
          label="Filled Error"
        />
        <FloatingLabel
          buttonStyle="outlined"
          error
          label="Outlined Error"
        />
        <FloatingLabel
          buttonStyle="standard"
          error
          label="Standard Error"
        />
      </div>
    </>
  )
}


Sizes#

Use the small and default sizes of the floating label input fields from the following example.

Edit on GitHub

  • React TypeScript
'use client';

import { div } from 'flowbite-react';

export default function FloatingLabel() {
  return (
    <>
      <div className="grid grid-flow-col justify-stretch space-x-4">
        <FloatingLabel
          buttonStyle="filled"
          label="Small Filled"
          sizing="sm"
        />
        <FloatingLabel
          buttonStyle="outlined"
          label="Small Outlined"
          sizing="sm"
        />
        <FloatingLabel
          buttonStyle="standard"
          label="Small Standard"
          sizing="sm"
        />
      </div>
      <div className="grid grid-flow-col justify-stretch space-x-4">
        <FloatingLabel
          buttonStyle="filled"
          label="Default Filled"
        />
        <FloatingLabel
          buttonStyle="outlined"
          label="Default Outlined"
        />
        <FloatingLabel
          buttonStyle="standard"
          label="Default Standard"
        />
      </div>
    </>
  )
}


Helper text#

Add a helper text in addition to the label if you want to show more information below the input field.

Edit on GitHub

Remember, contributions to this topic should follow our Community Guidelines.

  • React TypeScript
'use client';

import { FloatingLabel } from 'flowbite-react';

export default function FloatingLabel() {
  return (
    <FloatingLabel
      buttonStyle="filled"
      helperText="Remember, contributions to this topic should follow our Community Guidelines."
      label="Floating Helper"
    />
  )
}