Tailwind CSS
Utility-first styling that keeps design decisions consistent and colocated with markup; our recommended default for new projects.
Beginner · about 6 hours · difficulty 2/5
Learn first: Custom Properties and Modern CSS Features, Build Tools and Bundlers
Plain CSS works, but in a large app you fight naming, dead styles nobody dares delete, and specificity battles. Tailwind solves this by giving you small, single-purpose classes (flex, gap-4, text-sm, md:grid-cols-3) that you compose directly in markup. The build step scans your files and emits only the classes you actually used.
Why it is our default
- Consistency: spacing, colours and font sizes come from a shared scale, so you stop inventing
margin: 13px. - Locality: the styles for a component live in the component. Deleting the component deletes its styles.
- Speed: no context switching between files, and responsive or state variants are just prefixes:
hover:,focus-visible:,dark:,md:. - Ecosystem: shadcn/ui, many templates and most modern React tooling assume it.
How to use it well
- Configure your theme (colours, fonts, radii) with CSS variables so the design system lives in one place.
- Extract components, not
@applysoup. If a button's class list repeats, make aButtoncomponent. - Use a class-merging helper (
clsxplustailwind-merge) for conditional classes and overrides. - Install the editor extension for autocomplete and class sorting.
Pitfalls
- Tailwind is still CSS. If you do not understand flexbox, grid and the box model, utilities will not save you.
- Never build class names dynamically (
"bg-" + color); the scanner cannot see them. Map values to full class strings. - Long class lists are fine, but readable ordering and extraction into components matter.
Good enough to move on
You can build a responsive, dark-mode-aware card grid and navbar using only utilities, customise the theme colours, and explain why dynamic class strings break.
Key concepts
- Utility-first mindset
- Responsive and state variants
- Theme configuration with CSS variables
- Dark mode
- Conditional classes with clsx and tailwind-merge
- Extracting components vs @apply
- Arbitrary values and plugins
Other options for this step
- CSS Modules: Write normal CSS files whose class names are scoped to one component automatically, with zero runtime cost.
- Sass and Preprocessors: Variables, nesting, mixins and partials compiled to CSS; still common in existing codebases even though native CSS has caught up.
- CSS-in-JS: Style components with JavaScript (styled-components, Emotion) or zero-runtime tools (vanilla-extract, Panda); know the trade-offs.
Mini project
Rebuild one of your earlier HTML/CSS pages with Tailwind: responsive navigation, a card grid and a pricing table, with a working dark mode toggle driven by a class on the html element.
Check yourself
Why does writing className={`text-${size}`} fail in production, and how do you fix it?
Free resources
- Tailwind CSS Documentation (Tailwind CSS)
- Styling with utility classes (Tailwind CSS)