Hey there, fellow code wizards! ๐ Are you tired of those same old boring input fields? Well, get ready to spice up your forms without touching a single line of JavaScript! Today, we're diving into the magical world of Tailwind CSS to create some eye-catching, animated input fields that'll make your users go "Woah!" ๐ฎ
The Secret Sauce ๐งช
Here's a tasty snippet that'll transform your humble input into a search bar with style:
<section class="grid h-screen place-content-center bg-slate-900">
<div class="rounded-md bg-blue-100 p-8">
<div class="relative flex w-72 items-center gap-1 border-b-4 border-blue-400 py-1 after:absolute after:-bottom-1 after:h-1 after:w-full after:origin-center after:scale-x-0 after:bg-blue-800 after:transition after:duration-300 after:content-[''] has-[:focus]:after:scale-x-100">
๐
<input type="text" class="peer z-10 w-full bg-transparent text-sm outline-none [&::-placeholder-shown]:bg-red-500" placeholder="" />
<span class="absolute left-8 select-none text-sm font-semibold text-blue-800 transition-all peer-[:focus]:left-3 peer-[:not(:placeholder-shown)]:left-3 peer-[:focus]:-translate-y-8 peer-[:not(:placeholder-shown)]:-translate-y-8">Search </span>
</div>
</div>
</section>
What's the Magic Here? โจ
Smooth Underline Animation: We're using the
after
pseudo-element to create a slick underline that grows when the input is focused. No JavaScript required!Floating Label: The label starts inside the input and gracefully floats up when you start typing or focus on the input. It's all thanks to Tailwind's
peer
class and some clever positioning.Magnifying Glass Icon: We've thrown in a little ๐ emoji for that extra search bar feel. Feel free to swap it out with your favorite icon!
Responsive Design: The input adjusts nicely to different screen sizes, thanks to Tailwind's utility classes.
Preview Link
Tailwind Playground: https://play.tailwindcss.com/YEKzJsT140
Why It's Awesome ๐
No JavaScript: This is all pure CSS magic, folks! Your page stays lean and mean.
Easy to Customize: Tweak the colors, sizes, and transitions to match your brand in seconds.
Accessible: The floating label ensures your form stays accessible and user-friendly.
Wrap Up ๐
There you have it! A slick, animated input field that'll make your forms stand out from the crowd. And the best part? It's all achieved with the power of Tailwind CSS. No extra JavaScript, no client-side logic โ just pure, efficient styling.
So go ahead, copy this snippet into your project and watch your boring old inputs transform into interactive masterpieces. Your users (and your designer) will thank you!
Happy coding, and may your forms always be Fancy or Professional. ๐จโจ