When there’s a value already defined, <label>s will automatically adjust to their floated position.

Floating labels - 图2

  1. <form class="form-floating">
  2. <input type="email" class="form-control" id="floatingInputValue" placeholder="name@example.com" value="test@example.com">

By default, <textarea>s with .form-control will be the same height as <input>s.

Floating labels - 图4

  1. <div class="form-floating">
  2. <textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea"></textarea>
  3. <label for="floatingTextarea">Comments</label>
  4. </div>

Other than , floating labels are only available on .form-selects. They work in the same way, but unlike <input>s, they’ll always show the <label> in its floated state.

Floating labels - 图6

  1. <div class="form-floating">
  2. <select class="form-select" id="floatingSelect" aria-label="Floating label select example">
  3. <option value="1">One</option>
  4. <option value="2">Two</option>
  5. <option value="3">Three</option>
  6. </select>
  7. <label for="floatingSelect">Works with selects</label>