How to Style Form Inputs with Tailwind CSS Plugin

Tailwind CSS offers a complete form plugin to style all of the standard HTML input fields, however, there are times when you may need to customize these fields for your own theme or brand.
The good news is that the form plugin offers a couple strategies to customize and style Tailwind CSS form inputs.
In this article, I'll show some of the options to achieve any design theme your project might need.
What is the Tailwind CSS form plugin?
Tailwind CSS framework officially provides a complete form plugin named @tailwindcss/forms, which is a full reset on all of the standard form input element styling.
It's not included by default but for those that would rather work with pure HTML input fields, it makes this possible with minimal configuration.
Why use the Tailwind CSS form plugin?
It provides a basic Tailwind CSS theme over standard unstyled form input elements which can vary in each browser.
With so many component libraries out there, sometimes its just easier to work with standard form input elements.
Overall, it just adds completeness to the Tailwind CSS framework.
Getting started with Tailwind CSS form plugin
If you're just starting out, there's a simple configuration and it requires installing the plugin first.
1npm install @tailwindcss/forms
Once the plugin is installed, you need to add it to the tailwind.conf.ts configuration file.
1import type { Config } from 'tailwindcss';2import twFormsPlugin from '@tailwindcss/forms';34const config: Config = {5 // other config here67 // plugins8 plugins: [9 twFormsPlugin,10 ],11};12export default config;
And just to make sure it's working, here's a simple form snippet you can use to verify.
1<section className="w-full mx-auto p-10 antialiased">2 <form>3 <h2 className="text-2xl font-bold mb-10">Tailwind CSS Form Plugin</h2>4 <div className="grid grid-cols-1 sm:grid-cols-12 gap-6">5 <div className="flex-col sm:col-span-8 space-y-3">6 <label>Input (text)</label>7 <input8 type="text"9 className="w-full"10 placeholder="Enter some text..."11 />12 </div>13 <div className="flex-col sm:col-span-8 space-y-3">14 <label className="">Input (email)</label>15 <input16 type="email"17 className="w-full"18 placeholder="lloyd@example.com"19 />20 </div>21 <fieldset className="block sm:col-span-8">22 <legend>Checkboxes</legend>23 <div className="mt-2">24 <div>25 <label className="inline-flex items-center">26 <input type="checkbox" />27 <span className="ml-2">Option 1</span>28 </label>29 </div>30 <div>31 <label className="inline-flex items-center">32 <input type="checkbox" />33 <span className="ml-2">Option 2</span>34 </label>35 </div>36 <div>37 <label className="inline-flex items-center">38 <input type="checkbox" />39 <span className="ml-2">Option 3</span>40 </label>41 </div>42 </div>43 </fieldset>44 </div>45 </form>46 </section>
You should see the following form fields with the default theme. In most cases these fields look pretty good already and are far better than unstyled browser default fields.




