Skip to content

Floating Label

A copy-paste toggles & inputs component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

Toggles & InputsHTMLCSSany framework

Copy into your project

HTML
<!-- Floating Label — label floats up on focus / when filled
     The placeholder=" " (a single space) drives the CSS state. -->
<div class="nuda-floating-label">
  <input class="nuda-floating-label__input" type="text" id="email" placeholder=" " />
  <label class="nuda-floating-label__label" for="email">Email address</label>
</div>
CSS
/* ── Floating Label ──────────────────────────────────────────
   Uses :placeholder-shown + :focus to float the label up.
   Customize: --nuda-fli-clr for the accent color.
   ──────────────────────────────────────────────────────────── */
.nuda-floating-label {
  --nuda-fli-clr: #e4ff54;
  position: relative;
  width: 240px;
}

.nuda-floating-label__input {
  width: 100%;
  padding: 18px 14px 8px;
  background: #0c0c10;
  color: #fafafa;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.nuda-floating-label__input:focus {
  border-color: var(--nuda-fli-clr);
  box-shadow: 0 0 0 3px rgba(228, 255, 84, 0.18);
}

.nuda-floating-label__label {
  position: absolute;
  left: 14px;
  top: 15px;
  color: #777;
  font-size: 14px;
  pointer-events: none;
  transform-origin: left top;
  transition: transform 0.2s ease, color 0.2s ease;
}

.nuda-floating-label__input:focus + .nuda-floating-label__label,
.nuda-floating-label__input:not(:placeholder-shown) + .nuda-floating-label__label {
  transform: translateY(-9px) scale(0.74);
  color: var(--nuda-fli-clr);
}

/* ── Accessibility ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .nuda-floating-label__label,
  .nuda-floating-label__input { transition: none; }
}

How to use Floating Label

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More toggles & inputs components

← Browse all NudaUI components