Skip to main content

Floating labels

Labels that float over their form controls.

Bootstrap’s floating labels docs describe the markup and CSS.

Example

Put a bsLabel and then a bsFormControl in a bsFormFloating. The label comes first so screen readers announce it before the value. Text controls need a non-empty placeholder, which Bootstrap’s CSS uses to detect an empty control. It stays hidden until the control is focused.

HTML
<div class="vstack gap-3">
  <div bsFormFloating>
    <label bsLabel>Email address</label>
    <input type="email" bsFormControl placeholder="name@example.com" autocomplete="email" />
  </div>
  <div bsFormFloating>
    <label bsLabel>Password</label>
    <input type="password" bsFormControl placeholder="Password" autocomplete="current-password" />
  </div>
</div>

Validation

Validation styles work as for other controls. Put the floating label in a bsFormField for feedback.

Please enter a valid email address.
<div bsFormField>
  <div bsFormFloating>
    <label bsLabel>Email address</label>
    <input type="email" bsFormControl placeholder="name@example.com" [formControl]="email" />
  </div>
  <div bsInvalidFeedback>Please enter a valid email address.</div>
</div>

Textareas

For a taller textarea, set the --bs-form-floating-height CSS variable on the wrapper instead of rows.

HTML
<div class="vstack gap-3">
  <div bsFormFloating>
    <label bsLabel>Comments</label>
    <textarea bsFormControl placeholder="Leave a comment here"></textarea>
  </div>
  <div bsFormFloating style="--bs-form-floating-height: 100px">
    <label bsLabel>Longer comments</label>
    <textarea bsFormControl placeholder="Leave a comment here"></textarea>
  </div>
</div>

Selects

Selects always show the floated label. Selects with size or multiple aren’t supported.

HTML
<div bsFormFloating>
  <label bsLabel>Works with selects</label>
  <select bsFormControl>
    <option selected>Open this select menu</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
</div>

Date and time

Date, time, datetime-local, month and week inputs also always show the floated label. They don’t support placeholders like text inputs, so they don’t need one.

HTML
<div class="vstack gap-3">
  <div bsFormFloating>
    <label bsLabel>Date</label>
    <input type="date" bsFormControl />
  </div>
  <div bsFormFloating>
    <label bsLabel>Time</label>
    <input type="time" bsFormControl />
  </div>
</div>

Disabled and plain text

Disabled controls and bsFormControl="plaintext" work too, for example to switch between editing and showing a value.

HTML
<div class="vstack gap-3">
  <div bsFormFloating>
    <label bsLabel>Disabled email</label>
    <input type="email" bsFormControl placeholder="name@example.com" disabled />
  </div>
  <div bsFormFloating>
    <label bsLabel>Plain text email</label>
    <input
      type="email"
      bsFormControl="plaintext"
      readonly
      placeholder="name@example.com"
      value="name@example.com" />
  </div>
</div>

Input groups

Floating labels also work in a bsInputGroup. The wrapper mirrors the control’s validation state, so the group’s borders stay right.

@
HTML
<div bsInputGroup>
  <span bsInputGroupText>&#64;</span>
  <div bsFormFloating>
    <label bsLabel>Username</label>
    <input bsFormControl placeholder="Username" />
  </div>
</div>

Always floating

Add always to keep the label floated and the placeholder visible, even when the control is empty and unfocused.

HTML
<div class="vstack gap-3">
  <div bsFormFloating always>
    <label bsLabel>Email address</label>
    <input type="email" bsFormControl placeholder="name@example.com" autocomplete="email" />
  </div>
  <div bsFormFloating always>
    <label bsLabel>Password</label>
    <input type="password" bsFormControl placeholder="••••••••" autocomplete="new-password" />
  </div>
</div>

Layout

In a grid, put floating labels inside columns.

HTML
<div class="row g-2">
  <div class="md:col">
    <div bsFormFloating>
      <label bsLabel>Email address</label>
      <input type="email" bsFormControl placeholder="name@example.com" value="mdo@example.com" />
    </div>
  </div>
  <div class="md:col">
    <div bsFormFloating>
      <label bsLabel>Works with selects</label>
      <select bsFormControl>
        <option selected>Open this select menu</option>
        <option value="1">One</option>
      </select>
    </div>
  </div>
</div>

API

BsFormFloating

Selector: [bsFormFloating] · Exported as: bsFormFloating

Inputs

NameTypeDefaultDescription
alwaysbooleanfalseKeeps the label floated and the placeholder visible.

Methods

NameTypeDescription
controlIdSignal<string | null>Id of the control inside the wrapper.