Floating labels
The label sits inside the field like a hint, and floats up to the top edge as soon as you type, so the field is never left without its name. A compact look for sign-in and checkout forms.
Floating labels
<form class="stack gap-4 max-w-sm" onsubmit="event.preventDefault()">
<div class="form-floating">
<input class="form-control" id="fl-email" type="email" placeholder="you@example.com" autocomplete="email">
<label for="fl-email">Email</label>
</div>
<div class="form-floating">
<input class="form-control" id="fl-pass" type="password" placeholder=" " autocomplete="current-password">
<label for="fl-pass">Password</label>
</div>
<div class="form-floating">
<select class="form-select" id="fl-country"><option>Canada</option><option>Philippines</option><option>United Kingdom</option></select>
<label for="fl-country">Country</label>
</div>
<div class="form-floating">
<textarea class="form-control" id="fl-note" placeholder=" "></textarea>
<label for="fl-note">A note for the delivery</label>
</div>
<button class="btn btn-brand" type="submit">Continue</button>
</form>How it works
<div class="form-floating">
<input class="form-control" id="email" type="email" placeholder=" ">
<label for="email">Email</label>
</div>
- The field comes before its label, and it must have a placeholder (a single space is enough): that's how CSS knows whether it is empty. A real placeholder shows once the field has focus, as an example.
- Selects always show their label up top (they always have a value).
- Validation works as usual:
.is-invalidturns the label red too. Put a.form-errorafter the.form-floating.
Floating labels are compact but harder to scan in long forms; for those, the normal label above the field is clearer.