This example demonstrates styling an input field and addresses a common pitfall regarding browser default styles.
Gotcha: Browser Default Styles & The Forms Plugin
While classes like
border
,
rounded
,
px-3
, and
py-2
help in styling input fields,
you might notice inconsistencies across different browsers or find it challenging to override all default browser styles (e.g., specific focus rings, heights, or native appearances for certain input types).
The Key Issue: Browsers have their own default stylesheets for form elements, which can vary significantly. Applying Tailwind utilities directly might not always produce the exact same result everywhere or easily override all inherent styles without a proper reset.
Highly Recommended Solution:
Use the
@tailwindcss/forms
plugin. This official plugin provides a basic reset for form elements, making them much easier to style consistently with utility classes. It essentially "unstyles" them to a common baseline.
(Note: This CDN example cannot include the
@tailwindcss/forms
plugin as it typically requires a build step. In a real project, you would install and configure it in your `tailwind.config.js` file.)
Without the plugin, you might need to write more verbose utility combinations or even custom CSS to fight browser defaults. The input above is styled with the basic utilities, but for production applications, the forms plugin is a huge time-saver and ensures better consistency.