Snippets Input

CSS-Only Material Inputs with Floating Labels (Bootstrap 5)

Text fields with floating labels in filled and outlined styles, with focus, helper text and validation states, built with CSS only.

Bootstrap 5 No jQuery Aug 2019 6.9K views

<section class="wdw-stage mi-stage">
  <div class="container" style="max-width:920px">
    <div class="text-center mb-4 mb-md-5">
      <span class="wdw-eyebrow">Form fields</span>
      <h2 class="wdw-heading h2 mb-2">Material-style text fields</h2>
      <p class="wdw-muted mb-0 mx-auto" style="max-width:520px">Floating-label inputs in filled and outlined styles, shown in their neutral, focused, valid and invalid states.</p>
    </div>
    <div class="row g-4">
      <div class="col-md-6">
        <div class="wdw-card p-4 p-md-5 h-100">
          <h3 class="h6 fw-bold mb-4">Filled</h3>
          <form class="d-grid gap-3 mi-filled" novalidate>
            <div class="mi-item"><div class="form-floating"><input type="text" class="form-control is-valid" id="mi-f-name" placeholder="Name" aria-describedby="mi-f-name-h" value="Ava Morgan" autocomplete="name"><label for="mi-f-name">Name</label></div><div class="mi-help" id="mi-f-name-h">Looks good.</div></div>
            <div class="mi-item"><div class="form-floating"><input type="email" class="form-control is-invalid" id="mi-f-email" placeholder="Email" aria-describedby="mi-f-email-h" value="ava.morgan" autocomplete="email"><label for="mi-f-email">Email</label></div><div class="mi-help" id="mi-f-email-h">Enter a full address, like [email protected].</div></div>
            <div class="mi-item"><div class="form-floating has-eye"><input type="password" class="form-control mi-focus" id="mi-f-pass" placeholder="Password" aria-describedby="mi-f-pass-h" autocomplete="new-password" minlength="8" required><label for="mi-f-pass">Password</label><button type="button" class="mi-eye" aria-label="Show password" aria-pressed="false"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/></svg></button></div><div class="mi-help" id="mi-f-pass-h">At least 8 characters.</div></div>
            <div class="mi-item"><div class="form-floating"><input type="number" class="form-control" id="mi-f-num" placeholder="Seats" aria-describedby="mi-f-num-h" inputmode="numeric" min="1"><label for="mi-f-num">Seats</label></div><div class="mi-help" id="mi-f-num-h">Digits only.</div></div>
          </form>
        </div>
      </div>
      <div class="col-md-6">
        <div class="wdw-card p-4 p-md-5 h-100">
          <h3 class="h6 fw-bold mb-4">Outlined</h3>
          <form class="d-grid gap-3 mi-outlined" novalidate>
            <div class="mi-item"><div class="form-floating"><input type="text" class="form-control is-valid" id="mi-o-name" placeholder="Name" aria-describedby="mi-o-name-h" value="Ava Morgan" autocomplete="name"><label for="mi-o-name">Name</label></div><div class="mi-help" id="mi-o-name-h">Looks good.</div></div>
            <div class="mi-item"><div class="form-floating"><input type="email" class="form-control is-invalid" id="mi-o-email" placeholder="Email" aria-describedby="mi-o-email-h" value="ava.morgan" autocomplete="email"><label for="mi-o-email">Email</label></div><div class="mi-help" id="mi-o-email-h">Enter a full address, like [email protected].</div></div>
            <div class="mi-item"><div class="form-floating has-eye"><input type="password" class="form-control mi-focus" id="mi-o-pass" placeholder="Password" aria-describedby="mi-o-pass-h" autocomplete="new-password" minlength="8" required><label for="mi-o-pass">Password</label><button type="button" class="mi-eye" aria-label="Show password" aria-pressed="false"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/></svg></button></div><div class="mi-help" id="mi-o-pass-h">At least 8 characters.</div></div>
            <div class="mi-item"><div class="form-floating"><input type="number" class="form-control" id="mi-o-num" placeholder="Seats" aria-describedby="mi-o-num-h" inputmode="numeric" min="1"><label for="mi-o-num">Seats</label></div><div class="mi-help" id="mi-o-num-h">Digits only.</div></div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.