What Is New in Tailwind CSS 1.5
| Category | Highlights |
|---|---|
| New Features | Component variants support, responsive container variants, focus-visible variant, checked variant |
| Breaking Changes | One accidental breaking change introduced; fixed in v1.5.1 |
How do I enable variants for component classes in Tailwind CSS 1.5?
You can now generate responsive and other variants for component classes using the new variants option in the plugin API or the @layer directive.
- When adding components via
addComponents, pass a second argument withvariants: ['responsive'](or any other variant you need). - Alternatively, use the array shorthand:
addComponents({'.card': {/* ... */}}, ['responsive']). - For plain CSS, wrap your component rules in
@layer componentsand@responsiveto let Tailwind purge correctly.
plugin(function ({ addComponents }) {
addComponents({
'.card': {
/* component styles */
}
}, {
variants: ['responsive']
})
})
Can the container utility be responsive in Tailwind CSS 1.5?
Yes, the container class now supports responsive variants out of the box.
- Apply
md:containerto lock the container width only at medium breakpoints and above. - Additional variants such as
focusorgroup-hovercan be enabled via thevariants.containerarray intailwind.config.js.
<div class="md:container">
<!-- content -->
</div>
What is the new focus-visible variant and when should I use it?
The focus-visible variant lets you apply styles only when an element receives focus via keyboard navigation, keeping mouse interactions untouched.
- Enable it by adding
focus-visibleto the desired utilities in thevariantssection oftailwind.config.js. - Typical use case:
focus-visible:outline-none focus-visible:shadow-outlineon buttons. - Browser support is still limited; consider the WICG
focus-visiblepolyfill or thepostcss-focus-visibleplugin for broader coverage.
<button class="focus-visible:outline-none focus-visible:shadow-outline">
Click me
</button>
How can I style checked form controls with Tailwind CSS 1.5?
The new checked variant enables conditional styling of checkboxes and radio buttons.
- Add
checkedto the utilities you want to respond to the:checkedpseudo-class. - Enable it in
tailwind.config.jsunder the appropriate utility'svariantsarray. - Example:
bg-white checked:bg-blue-500changes the background when the input is checked.
<input type="checkbox" class="bg-white checked:bg-blue-500" />
Frequently Asked Questions
Do I need to modify my plugin code to use component variants in Tailwind CSS 1.5?
You add the variant by passing ['responsive'] as the second argument to addComponents or by using @layer components with @responsive.
How do I enable the focus-visible variant globally?
Add focus-visible to the desired utilities in the variants section of tailwind.config.js.
Can I combine responsive and checked variants on the same class?
Yes, you can chain them like md:checked:bg-blue-500.
Is the responsive container variant enabled by default?
Yes, responsive variants for container are on by default.
What breaking change should I be aware of when upgrading to 1.5?
An accidental breaking change was introduced and fixed in v1.5.1, so upgrade to 1.5.1 to avoid issues.
Do I need a polyfill for the focus-visible variant?
Browser support is limited, so using the WICG focus-visible polyfill or postcss-focus-visible plugin is recommended.