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.
<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>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.mi-item .mi-help{min-height:1.25rem;font-size:.8rem;color:var(--bs-secondary-color);padding:.3rem .25rem 0}
.mi-item:has(.is-invalid) .mi-help{color:var(--bs-danger-text-emphasis)}
.mi-item:has(.is-valid) .mi-help{color:var(--bs-success-text-emphasis)}
.mi-stage .form-control{background-image:none!important;padding-right:1rem}
.mi-stage input[type=number]{-moz-appearance:textfield;appearance:textfield}
.mi-stage input::-webkit-outer-spin-button,.mi-stage input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
.mi-stage .has-eye .form-control{padding-right:3rem}
.mi-eye{position:absolute;right:.35rem;top:50%;transform:translateY(-50%);z-index:5;width:44px;height:44px;border:0;background:transparent;color:var(--bs-secondary-color);border-radius:.75rem;display:inline-flex;align-items:center;justify-content:center}
.mi-eye:hover{color:var(--bs-emphasis-color)}
.mi-eye:focus-visible{outline:2px solid var(--bs-primary);outline-offset:-2px}
.mi-stage .is-invalid~label,.mi-stage .is-invalid:focus~label{color:var(--bs-danger-text-emphasis)}
.mi-stage .is-valid~label{color:var(--bs-success-text-emphasis)}
/* filled: bottom-border only */
.mi-filled .form-control{background:var(--bs-secondary-bg);border:0;border-bottom:2px solid var(--bs-secondary-color);border-radius:.75rem .75rem 0 0;box-shadow:none}
.mi-filled .form-control:hover{background:var(--bs-tertiary-bg)}
.mi-filled .form-control:focus,.mi-filled .form-control.mi-focus{background:var(--bs-primary-bg-subtle);border-bottom-color:var(--bs-primary);box-shadow:none}
.mi-filled .form-control.is-valid{border-bottom-color:var(--bs-success)}
.mi-filled .form-control.is-invalid{border-bottom-color:var(--bs-danger)}
.mi-filled .form-floating>label::after{display:none}
/* outlined: stronger border, notch label (Bootstrap's own) */
.mi-outlined .form-control{border:1.5px solid var(--bs-secondary-color)}
.mi-outlined .form-control:hover{border-color:var(--bs-emphasis-color)}
.mi-outlined .form-control:focus,.mi-outlined .form-control.mi-focus{border-color:var(--bs-primary);box-shadow:0 0 0 1px var(--bs-primary)}
.mi-outlined .form-control.is-valid{border-color:var(--bs-success);box-shadow:none}
.mi-outlined .form-control.is-invalid{border-color:var(--bs-danger);box-shadow:none}
.mi-focus~label{color:var(--bs-primary)}
.mi-filled .form-control.mi-focus~label,.mi-filled .form-control:focus~label{color:var(--bs-primary)}
.mi-outlined .form-floating>.form-control{padding-top:1.625rem}
.mi-outlined .form-floating>.form-control:focus~label::after,.mi-outlined .form-floating>.form-control:not(:placeholder-shown)~label::after{background:var(--bs-body-bg)}
.mi-stage .form-floating>.form-control.mi-focus~label{opacity:.65;transform:scale(.85) translateY(-.5rem) translateX(.15rem)}
(function () {
function initFloatingFields() {
document.querySelectorAll('.mi-eye').forEach(function (btn) {
var input = btn.parentElement.querySelector('input');
if (!input) return;
btn.addEventListener('click', function () {
var show = input.type === 'password';
input.type = show ? 'text' : 'password';
btn.setAttribute('aria-pressed', String(show));
btn.setAttribute('aria-label', show ? 'Hide password' : 'Show password');
});
});
document.querySelectorAll('.mi-stage .form-control').forEach(function (input) {
input.addEventListener('focus', function () { input.classList.remove('mi-focus'); });
input.addEventListener('blur', function () {
if (!input.value) { input.classList.remove('is-valid', 'is-invalid'); return; }
var ok = input.checkValidity();
input.classList.toggle('is-valid', ok);
input.classList.toggle('is-invalid', !ok);
});
});
}
initFloatingFields();
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.