A decade of Canvas at your command — powered by our custom AI engineStart Building →
Bootstrap 5Forms

Bootstrap 5 Form Floating Label

Bootstrap 5 floating labels are animated form labels that start inside the input field as placeholder text, then smoothly float above the field when the user types or the input receives focus. They save vertical space, look modern, and maintain label visibility at all times — solving the placeholder-label trade-off.

Primary Class

.form-floating

Common Use Cases

  • Compact contact forms
  • Login and signup pages
  • Newsletter email capture
  • Search inputs with inline labels
  • Multi-step wizard forms
  • Dark-themed modal forms

Variants & Classes

VariantDescription
Text inputStandard floating label over a text input.
TextareaFloating label over a multi-line textarea.
Select dropdownFloating label over a select element.
With validationGreen/red validation feedback alongside floating label.

Code Example

<div class="form-floating mb-3">
  <input type="email" class="form-control" id="emailInput"
    placeholder="[email protected]">
  <label for="emailInput">Email address</label>
</div>

<div class="form-floating mb-3">
  <textarea class="form-control" id="messageInput"
    style="height:120px" placeholder="Your message"></textarea>
  <label for="messageInput">Message</label>
</div>

<div class="form-floating">
  <select class="form-select" id="planSelect">
    <option selected>Select a plan</option>
    <option value="1">Starter</option>
    <option value="2">Pro</option>
  </select>
  <label for="planSelect">Plan</label>
</div>

Live Examples

Email Input

Standard floating label email input with placeholder animation.

Example 1

Textarea

Floating label over a multi-line textarea with fixed height.

Example 2

Select Dropdown

Floating label that works with select elements — label stays visible after selection.

Example 3

Canvas Framework Variants

The Canvas template extends Bootstrap 5 with 1,658+ component variants. Generate any of these using Canvas Builder:

  • Dark modal login form with floating labels
  • Newsletter capture with email floating label
  • Multi-step checkout with animated field labels
  • Contact form with icon + floating label hybrid
  • Search bar with floating label in navbar

Best Practices

Always provide a placeholder attribute

Floating labels require a placeholder attribute (even if empty) to trigger the CSS animation. Without it, the label won't float above the input on focus.

Use mb-3 on each floating wrapper for spacing

form-floating elements don't have built-in bottom margin. Add mb-3 to each wrapper div to maintain consistent vertical rhythm in your form.

Match the label 'for' to the input 'id'

The label's for attribute must exactly match the input's id. This association enables clicking the label to focus the input and is required for screen reader accessibility.

FAQ

Why isn't my Bootstrap 5 floating label animating?
Floating labels require a placeholder attribute on the input — even an empty one. The CSS uses the :placeholder-shown pseudo-class to detect whether the label should float. Without placeholder, the animation won't trigger.
Can I use floating labels with Bootstrap 5 validation?
Yes — add .is-valid or .is-invalid to the form-control inside the form-floating wrapper. The validation icons and colours apply correctly. Use .valid-feedback and .invalid-feedback siblings outside the wrapper.