Skip to content

Floating Label Inputs

Bootstrap 5 floating label inputs for text, email, select and textarea, styled as filled fields with validation, read-only and disabled states.

Also known as: material style inputs, filled form fields, floating label form, animated label inputs

Floating Label Inputs live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A set of Bootstrap 5 floating label inputs for text, email, select and textarea fields, restyled as soft "filled" fields with a strong bottom line, plus read-only and disabled examples. Use it for profile settings, account pages, checkout steps or any form where compact labels save space.

How it works

The root is section.fl-fields. A white .fl-panel splits into an intro column (col-lg-4) with a short legend and the .fl-form (col-lg-8). Every field uses Bootstrap's form-floating wrapper: the control comes first, then its label, and a placeholder is required so Bootstrap can detect an empty field with :placeholder-shown. The selects float their label permanently, and the .fl-bio textarea gets a fixed height so the floated label has room.

The CSS replaces the default box with a tinted background, a 2px bottom border and rounded top corners. On focus the line and label switch to the accent color, .is-valid and .is-invalid change the line to green or red, [readonly] uses a dashed line and :disabled turns gray. The textarea label's ::after mask is recolored so scrolled text never shows through.

The script validates only the [required] fields, and only after the user leaves one (blur) with a value; from then on it re-checks on input or change. Invalid fields get aria-invalid and their error text through aria-describedby. The textarea input event updates .fl-count, the reset event clears every state, and submit focuses the first invalid field or writes a confirmation into .fl-status.

Customization

  • --fl-accent, --fl-accent-hover and --fl-accent-rgb in .fl-fields: change the teal focus line, focused label color, chip and buttons.
  • --fl-field-bg and --fl-field-line in .fl-fields: set the fill color and the resting bottom line of every field.
  • --fl-ok and --fl-err in .fl-fields: recolor the valid and invalid states and the legend dots.
  • --fl-field-radius in .fl-fields: use 0 for square fields or a larger value for softer corners.
  • --fl-bio-height in .fl-fields: make the textarea taller or shorter.
  • maxlength="200" on .fl-bio: change the bio limit; the counter reads it automatically.
  • col-md-6 on the field columns: switch to col-12 for a single-column form.
  • The window.setTimeout call in the submit handler: replace it with a fetch() to your API.

Use cases

  • Profile settings: compact floating labels fit text, email, select and bio fields into a small panel
  • Account pages: read-only and disabled examples show locked fields such as a username
  • Checkout steps: labels that move out of the way save vertical space on short forms
  • Contact forms: a bio textarea with a character counter and validation after leaving each field

Accessibility

Every control has a real label linked with for, and the labels stay visible after they float, unlike plain placeholders. Error messages are connected through aria-describedby only while a field is invalid, the textarea is always described by its counter, and .fl-status is a role="status" region. Validation waits until a field is left, so users are not interrupted while typing. Focus shows both a colored line and a focus ring, and transitions are disabled with prefers-reduced-motion: reduce.

Usage notes

Requires Bootstrap 5.3 and Bootstrap Icons. Keep the placeholder attribute on inputs and textareas; without it the label overlaps the text.

Floating Label Inputs at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Inputs
License
Free for personal and commercial use

Questions about this template

Can I use the Floating Label Inputs code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Floating Label Inputs – free Bootstrap 5 input template
Floating Label Inputs · free Bootstrap 5 input template

More Inputs

Password Strength Meter – free Bootstrap 5 input template

Password Strength Meter

Bootstrap 5 password input with show/hide toggle, four-step strength meter, live requirements checklist and confirmation match check.

Inputs with Icons and Add-ons – free Tailwind CSS input template

Inputs with Icons and Add-ons

Tailwind CSS input group examples with leading icons, text prefixes and suffixes, a currency select, password toggle, clear button and helper text.

Tag Input with Chips – free Bootstrap 6 input template

Tag Input with Chips

Dark Bootstrap 6 tag input that turns typed values into removable Chips, with suggestions, a tag limit, keyboard shortcuts and a live post preview.

Form Validation Styles – free Bootstrap 6 input template

Form Validation Styles

Bootstrap 6 signup form showing valid and invalid field states with specific feedback messages, a live status checklist and a simulated submit.

OTP Code Input – free Bootstrap 6 input template

OTP Code Input

Dark Bootstrap 6 OtpInput verification card with 6 digit slots, paste support, auto-advance, auto-verify on complete, error state and a resend countdown.

Password Input with Strength Meter – free Bootstrap 6 input template

Password Input with Strength Meter

Bootstrap 6 password field with show/hide toggle, the Strength meter, a live requirement checklist, confirm match, Caps Lock hint and a password generator.