Skip to content

Focus Underline

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

Toggles & InputsHTMLCSSany framework

Copy into your project

HTML
<!-- Focus Underline — underline grows from the center on focus -->
<div class="nuda-focus-underline">
  <input class="nuda-focus-underline__input" type="text" placeholder="Type here..." />
  <span class="nuda-focus-underline__bar"></span>
</div>
CSS
/* ── Focus Underline ─────────────────────────────────────────
   A scaleX(0)->scaleX(1) bar centred under the field.
   Customize: --nuda-fu-clr for the underline color.
   ──────────────────────────────────────────────────────────── */
.nuda-focus-underline {
  --nuda-fu-clr: #e4ff54;
  position: relative;
  width: 240px;
}

.nuda-focus-underline__input {
  width: 100%;
  padding: 10px 2px;
  background: transparent;
  color: #fafafa;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 14px;
  outline: none;
}

.nuda-focus-underline__input::placeholder { color: #666; }

.nuda-focus-underline__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--nuda-fu-clr);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}

.nuda-focus-underline__input:focus ~ .nuda-focus-underline__bar {
  transform: scaleX(1);
}

/* ── Accessibility ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .nuda-focus-underline__bar { transition: none; }
}

How to use Focus Underline

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