Polished text input, select, and textarea components with focus states using Tailwind CSS
Quick Answer
Tailwind CSS form inputs use border border-gray-300 rounded-lg px-3.5 py-2.5 with focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 for a polished, accessible focus state.
1<!-- Text input with label -->
2<div class="space-y-1.5">
3 <label for="email" class="block text-sm font-medium text-gray-700">Email address</label>
4 <input id="email" type="email" placeholder="you@example.com"
5 class="w-full px-3.5 py-2.5 text-sm border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 placeholder:text-gray-400 transition" />
6</div>
7
8<!-- Input with error state -->
9<div class="space-y-1.5">
10 <label for="username" class="block text-sm font-medium text-gray-700">Username</label>
11 <input id="username" type="text" value="taken_name"
12 class="w-full px-3.5 py-2.5 text-sm border border-red-400 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-red-400 bg-red-50 text-red-900 transition" />
13 <p class="text-xs text-red-600">This username is already taken.</p>
14</div>
15
16<!-- Select dropdown -->
17<div class="space-y-1.5">
18 <label for="role" class="block text-sm font-medium text-gray-700">Role</label>
19 <select id="role" class="w-full px-3.5 py-2.5 text-sm border border-gray-300 rounded-lg shadow-sm bg-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition">
20 <option value="">Select a role...</option>
21 <option value="developer">Developer</option>
22 <option value="designer">Designer</option>
23 <option value="manager">Manager</option>
24 </select>
25</div>
26
27<!-- Textarea -->
28<div class="space-y-1.5">
29 <label for="message" class="block text-sm font-medium text-gray-700">Message</label>
30 <textarea id="message" rows="4" placeholder="Write your message here..."
31 class="w-full px-3.5 py-2.5 text-sm border border-gray-300 rounded-lg shadow-sm resize-y focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 placeholder:text-gray-400 transition"></textarea>
32</div>
33
34<!-- Submit button -->
35<button type="submit" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-2.5 px-6 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-colors">Send message</button>Form inputs are among the most critical UI elements — poor styling leads to confusing user experiences. This collection of Tailwind CSS form components includes a standard text input with label, a select dropdown, a textarea, and error/success validation states. All components use consistent focus rings and spacing for a cohesive design.
Wrap the input in a relative div. Place the icon in an absolute left-3 top-1/2 -translate-y-1/2 span, then add pl-10 to the input so the placeholder text starts after the icon.
Add dark: variant classes alongside light ones: dark:bg-gray-800 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-indigo-400.
This free html code snippet for form input components is production-ready and copy-paste friendly. Whether you are building a web app, API, or frontend interface, this beginner-level example will help you implement form input components quickly and correctly.
All snippets in the Snippetly library follow html best practices and are tested for real-world use. You can adapt this code to work with React, Vue, Node.js, or any project that uses html.
Organise your team's code snippets with Snippetly. Share knowledge and boost productivity across your organisation.