Utility-first or utility-last?

Tailwind CSS is based on the "utility-first" approach, where the majority of styling is done using utility CSS classes. You can still add additional custom styles if needed if there is something that can't be achieved with utilities or would be better placed in a custom CSS stylesheet.

Utility-last is the opposite approach, where a small number of utilities are used alongside other CSS styles or another framework. This is common when adding a utility-based framework like Tailwind CSS to an existing project and you want to use it for a new page or component whilst keeping the existing styles.

This is what I did when I started learning Tachyons, and later Tailwind CSS. My project already had styling from another CSS framework, I started using utility classes and over time refactored until only utilities were used and the other styles could be removed.

You could do the opposite too, and refactor groups of utilities into a CSS component, either by using Tailwind's @apply directive or writing a plugin.

If you did want to use Tailwind for a small number of utilities, by default, it will only generate classes that are used within HTML or template files, but it can also be configured to only use the core modules that you specify - preventing Developers from using unwanted utility based on the rules for that project.

You could, of course, write your own utilities, or they're becoming common in other frameworks now too for things like padding, margin and colours.

Do you typically do styling utility-first or utility-last, or are you transitioning from one to the other?

- Oliver

P.S. Do you want to learn about automated testing in Drupal? Take my free 10-day email course and get daily lessons straight to your inbox.

Was this useful?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.