Tailwind CSS
A CSS framework of utility classes: tokens in CSS, only the rules in use generated, a consistent look across components.
FrontendUsing since 2019 · Featured project: Budzowska Fiutowski i Partnerzy
- Category
- Frontend
- Using since
- 2019
- Featured project
- Budzowska Fiutowski i Partnerzy
In practice
Tailwind CSS is my main choice for styling. I pick it when a site should look consistent and stay maintainable after hand-over: styles sit next to components, and colours and spacing live in one place. It is in the stack of Budzowska Fiutowski i Partnerzy and ENATIV Portfolio. For a single static page I would not reach for it.
What is Tailwind CSS?
Tailwind CSS is a CSS framework built on utility classes. Instead of naming classes and writing rules for them in a separate stylesheet, you compose the look from small single-purpose classes, such as spacing, colour or font size, and write them straight into the component markup. You then pick values from a defined system, not arbitrary numbers.
Tailwind treats source files as plain text, looks for class names in them and generates CSS only for the ones it actually found. The output file therefore holds what the site uses. There is one consequence: a class whose name is assembled from fragments goes undetected. The colours, typeface and breakpoints of a project you describe as theme variables, with the @theme directive in the CSS itself.
- Kind
- A CSS framework built on utility classes
- Styling
- Classes written in the component markup
- Project tokens
- Theme variables in CSS, the @theme directive
- Output CSS
- Only the classes found in the source
How I work with Tailwind CSS
I start with tokens, not classes. Before the first component exists, I settle the colours, spacing and typography as theme variables, so every change of look comes from one place.
Tokens in a CSS file
I describe the theme with the
@themedirective in a CSS file, with no separate config file. That is how ENATIV Portfolio is set up: the tokens live inglobals.cssand the project has notailwind.configfile.Components, not copies
A look that repeats goes into a component, not into a pasted list of classes. I describe variants, such as those of a button, with CVA in a separate file, and take accessible behaviour from Radix components. In the Code & Pepper team I worked with the Tailwind CSS and Radix UI pair on Gaia Lens, where the interface was redesigned for investor workflows.
Complete class names
I write class names in full and map variants to ready-made sets of classes, because Tailwind will not detect a class built from pieces. The generated CSS then holds what the page uses.
When it fits, and when it doesn't
Tailwind CSS makes sense where the look is made of repeatable components and should stay consistent after hand-over.
A good fit when
- A site or app in React and Next.js where the look lives in components.
- A site that should look the same on every screen and keeps colours and spacing in one place.
- A redesign of a site whose old stylesheet nobody understands any more.
- A team that changes the look itself after launch and does not want to hunt for rules in a foreign stylesheet.
Not a fit when
- A single static page that nobody will extend.
- A team that knows only plain CSS and has no time to learn class names.
- A project with a ready style system in another tool that must stay untouched.
When there are few styles and they belong to one component, plain CSS or CSS Modules is enough. The category filter in the knowledge hub of ENATIV Portfolio works that way.
Frequently asked questions
A site look that needs order?
Tell me who will change the look after launch and whether a visual design already exists. I will answer whether Tailwind CSS fits or plain CSS is enough.