Photo by Pankaj Patel on Unsplash
Unlocking the Power of Tailwind CSS: A Deep Dive into Hover, Focus, Hidden, and Other Essential Features
Tailwind CSS is one of the popular and fast-growing utility-based CSS frameworks that has its popularity only increasing with time. Tailwind v3.0 comes with some new and exciting features, updates, and changes that can help developers create more functional and dynamic designs for their websites. Here's a rundown of Tailwind CSS's new and latest features:
@tailwind base directive
One of the major changes in Tailwind CSS v3.0 is the @tailwind base
directive, which must be present for utilities like transforms, filters, and shadows to work appropriately. Previously, some developers were disabling Tailwind's base styles by excluding this directive, but in the new version, you should add it to your stylesheet, and disable preflight
in your corePlugins
configuration instead:
+ @tailwind base;
@tailwind components;
@tailwind utilities;
module.exports = {
// ...
corePlugins: {
preflight: false,
},
}
By enabling the @tailwind base
directive and disabling the preflight
core plugin, global base styles will be disabled without affecting utilities that rely on adding their own base styles to function correctly.
Renaming of the Screens layer
The @tailwind screens
layer has been renamed to @tailwind variants
. To implement this new naming convention, simply update the following code within your stylesheet:
/* ... */
- @tailwind screens;
+ @tailwind variants;
Though it may feel like a small change, it's important developers update this to ensure they are using the latest syntax.
Responsive font size utilities
Tailwind CSS v3.0 brings a brand new utility for relative font sizing, font-size-responsive
. The font-size-responsive
utility allows you to control the font size of your elements depending on the screen's width. It replaces the text-sm
and text-lg
utility classes, which were used to define text sizes for small and large screens separately.
<p class="text-blue-500 font-size-responsive">
This text will be default size on small screens and larger size on bigger screens.
</p>
The code above demonstrates how responsive font sizing can be used to achieve great typography across different devices.
New opacity and colors utilities
Tailwind CSS v3.0 expands the range of opacity and color utilities to empower designers to make better use of semantic color names. This release comes with the gray
color palette which includes warmGray
, trueGray
, gray
, coolGray
, and blueGray
.
Below is some code to demonstrate the new gray color palette in use:
<div class="bg-warmGray-100"></div>
<div class="bg-trueGray-200"></div>
<div class="bg-gray-300"></div>
<div class="bg-coolGray-400"></div>
<div class="bg-blueGray-500"></div>
Conclusion
Tailwind CSS v3.0 introduces some exciting new features and updates, including the @tailwind base
directive, responsive font sizing, new opacity and color utilities, and more. As a result, developers can now create more functional and dynamic designs with greater ease than ever before. By leveraging these changes and new utilities, developers can ensure that their website designs are more accessible, user-friendly, and visually appealing!