loading

BS5 Floating Labels

Floating Labels / Animated Labels

When labels are used, they often show up above the input field by default:

Email Label

By using floating labels, you can place the label inside the input field and have it move or animation when the input field is clicked:

Example

				
					<div class="form-floating mb-3 mt-3">
  <input type="text" class="form-control" id="email" placeholder="Enter email" name="email">
  <label for="email">Email</label>
</div>

<div class="form-floating mt-3 mb-3">
  <input type="text" class="form-control" id="pwd" placeholder="Enter password" name="pswd">
  <label for="pwd">Password</label>
</div>
				
			

Notes on floating labels: The placeholder property is necessary for every <input> element (even if it is not displayed), and the <label> elements have to appear after the <input> element.

Textarea

This also applies to textareas:

Example

				
					<div class="form-floating">
  <textarea class="form-control" id="comment" name="text" placeholder="Comment goes here"></textarea>
  <label for="comment">Comments</label>
</div>
				
			

Select Menus

Additionally, “floating-labels” are an option for some menus. They won’t, however, levitate or become animated. The label will always show up inside the pick menu, in the upper left corner:

Example

				
					<div class="form-floating">
  <select class="form-select" id="sel1" name="sellist">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
  </select>
  <label for="sel1" class="form-label">Select list (select one):</label>
</div>
				
			
Share this Doc

BS5 Floating Labels

Or copy link

Explore Topic