Skip to content

Instantly share code, notes, and snippets.

@marcospgp
Created April 21, 2025 13:13
Show Gist options
  • Save marcospgp/1cb3b77488a7f616cd06b6c4a082ed6e to your computer and use it in GitHub Desktop.
Save marcospgp/1cb3b77488a7f616cd06b6c4a082ed6e to your computer and use it in GitHub Desktop.
text input with animated underline in tailwind
<div className="relative">
<input
type="text"
ref={inputRef}
placeholder="flaborger the shenonions..."
className="peer relative z-10 focus:outline-none"
size={24}
/>
{/* Animated underline */}
<span
className={`absolute bottom-0 left-0 z-0 inline-block h-[1.5px] w-full ${error ? "bg-danger-500" : "bg-text-muted"} align-bottom`}
/>
<span className="absolute right-0 bottom-0 z-1 inline-block h-[1.5px] w-0 bg-text align-bottom transition-[width] ease-out peer-focus:left-0 peer-focus:w-full" />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment