Tailwind CSS' extensibility is one of its best features
As well as the library of utility CSS classes that Tailwind provides, the ability to easily add your own has been one of my main advantages of using it.
You can add your own CSS to a stylesheet within a specific layer, customise the theme settings within a tailwind.config.js file, and write your own custom plugins that you can reuse and even release as separate open-source projects.
Here is a complete plugin that I've added to some projects recently:
By adding these lines of JavaScript, Tailwind will generate a new set of utility classes that apply styles to both hover and focus states for an element - reducing the number of classes that need to be added and making it more maintainable.
Other plugins that I've written recently include creating different variants of buttons, styling elements within an HTML table (similar to the Tailwind typography plugin), and adding multi-theme support to make components themable with different colours.
The interesting thing is that the plugin API is how Tailwind itself generates its own classes, and I like the stability that provides.
However you extend Tailwind, the fact you can tweak and extend it for each project is great and something that you can't always do or do easily with other tools or frameworks.
- Oliver
Was this interesting?
About me
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.