Matthew C.
—You are using Tailwind CSS in your Next.js app. When you try to style a checkbox input, some Tailwind utility classes don’t work. For example, consider the following checkbox HTML input element:
<div class="p-6"> <input type="checkbox" className="h-16 w-16 cursor-pointer rounded-full text-green-600" /> </div>
The utility classes h-16
, w-16
, and cursor-pointer
work but the utility classes rounded-full
and text-green-600
do not. You can see this in the following Tailwind Play playground code demo.
To fix this issue, add the @tailwindcss/forms
plugin to your tailwind.config.js
configuration file:
/** @type {import('tailwindcss').Config} */ export default { theme: { extend: { // ... }, }, plugins: [require('@tailwindcss/forms')], }
This plugin does a basic reset of the CSS styles of form elements. It removes the default styling applied to form elements by different browsers. Some of these styles are important for accessibility such as applying an outline to input elements when they are in focus.
The plugin adds some basic default styling to the different form elements including styles that are important for accessibility. These default styles are easy to override with Tailwind utility classes.
Removing the default form element styles and then giving them basic default styles makes the styling consistent across different browsers and serves as a good starting point for styling the form elements.
The rounded-full
and text-green-600
styles don’t work without the style reset because the default styles applied by the browser, such as Chrome’s default HTML stylesheet, have a higher CSS specificity than the Tailwind utility classes.
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.