Styling with Tailwind CSS
Style React components quickly and consistently with utility classes, a shared design scale and component patterns.
Intermediate · about 5 hours · difficulty 2/5
Learn first: React Fundamentals
Tailwind CSS is the most common styling choice in new React and Next.js projects. Instead of writing separate CSS files, you compose small utility classes directly in your markup.
Why teams use it
- A built-in scale for spacing, colours and type keeps designs consistent.
- No naming debates and no dead CSS; unused classes are removed at build time.
- Responsive and state variants (md:, hover:, focus-visible:, dark:) are right next to the element they affect.
Working well with it
- Extract components, not custom CSS classes, when patterns repeat: a Button component with variants beats copying 15 classes.
- Use a helper like clsx or tailwind-merge for conditional classes.
- Configure theme colours and fonts once so the whole app follows your brand.
- Component libraries such as shadcn/ui give you accessible, copy-in components built on Tailwind.
Pitfalls
- Learning Tailwind without CSS. You will not know which utility you need, or why a layout breaks.
- Extremely long class strings repeated across files instead of extracting components.
- Ignoring focus styles because they are not in the design.
You are ready to move on when you can rebuild your internship board UI in Tailwind with a reusable Button and Card, dark mode, and a mobile-first responsive layout.
Key concepts
- Utility classes and the design scale
- Responsive and state variants
- Dark mode
- Theme configuration
- Component extraction with variants
- clsx and tailwind-merge
- shadcn/ui
Other options for this step
- Styling with CSS Modules: Write plain CSS scoped to each component, with no runtime cost and full access to modern CSS features.
Mini project
Restyle your internship board with Tailwind: a themed Button with primary, secondary and danger variants, responsive card grid, accessible focus states and a dark mode toggle.
Check yourself
The same 12 Tailwind classes appear on 20 buttons. What is the right way to remove the duplication?
Free resources
- Tailwind CSS Documentation (Tailwind CSS)
- shadcn/ui (shadcn/ui)