Utility-First Fundamentals

Utility-first CSS is a methodology that uses a set of low-level utility classes to build user interfaces directly in your HTML.

In traditional CSS, you'd write custom CSS rules to style your elements. For example, if you wanted to style a card, you'd create a .card class and define all the styles in a separate CSS file.

With Tailwind CSS, you combine utility classes like bg-white, rounded-lg, shadow-md, and p-6 to achieve the same result. This approach has several benefits:

Example

Here's a simple card component built using Tailwind CSS utility classes. Notice how the styling is applied directly to the elements themselves.

View Output

Common Concerns

You might be wondering if this approach results in "ugly" HTML with too many classes. While it can take some time to get used to, many developers find that the benefits of utility-first CSS far outweigh the initial learning curve.

Ultimately, you’ll need to weigh these stylistic trade-offs against your own workflow, but exploring the framework is a low-risk way to expand your toolkit and might just spark a new perspective on styling.

In the next page, we'll see how to handle different element states, like hover and focus, using Tailwind CSS utility classes.