Lesson 42 of 52Tailwind in practice
Tailwind in Real Teams
Read v3 and v4 codebases side by side, upgrade with the official tool, agree on team conventions, review Tailwind PRs, and answer the interview questions.
Learning Tailwind on a fresh project is one thing. Joining a team is another. The codebase might be three years old and use Tailwind version 3, with a JavaScript config file you have never seen. Five people write classes in five different orders. Someone has put forty @apply rules in one stylesheet, and a pull request adds mt-[13px] for the third time this week. This lesson is about the habits that keep Tailwind pleasant when many people share it: reading old and new setups, upgrading safely, agreeing on conventions, reviewing changes, and explaining your choices in an interview.
Reading a version 3 codebase
Tailwind version 4 came out in early 2025 and moved configuration from JavaScript into CSS. Plenty of production apps still run version 3, so you need to read both. The quickest way to tell them apart is the main CSS file.
/* styles/globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;// tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{js,ts,jsx,tsx}"],
darkMode: "class",
theme: {
extend: {
colors: {
brand: { 50: "#eef6ff", 600: "#2563eb" },
},
fontFamily: {
display: ["Fraunces", "serif"],
},
},
},
plugins: [require("@tailwindcss/typography")],
};/* app/globals.css */
@import "tailwindcss";
@plugin "@tailwindcss/typography";
@custom-variant dark (&:where(.dark, .dark *));
@theme {
--color-brand-50: #eef6ff;
--color-brand-600: #2563eb;
--font-display: "Fraunces", serif;
}Read the version 3 config as a translation table:
@tailwind base; components; utilities;are three directives that inject Tailwind's layers. In version 4 the single@import "tailwindcss";does the same job.contentlists the files Tailwind scans for class names. Version 4 finds your source files automatically and uses@sourcefor anything extra. If a class "does nothing" in a version 3 app, check whether its file matches thecontentglobs first.theme.extendadds tokens on top of the defaults, sobrand.600becomesbg-brand-600. Writing directly undertheme(withoutextend) replaces a whole group, which is the version 3 equivalent of--color-*: initial.darkMode: "class"makesdark:follow a.darkclass. In version 4 that is the@custom-variantline.pluginsloads extensions. In version 4 it is@pluginin CSS.
A few class names also changed between versions, which trips people up when copying code from old tutorials or Stack Overflow answers:
| Version 3 | Version 4 |
|---|---|
shadow-sm / shadow | shadow-xs / shadow-sm |
rounded-sm / rounded | rounded-xs / rounded-sm |
outline-none | outline-hidden |
bg-opacity-50 | bg-black/50 (opacity modifier) |
bg-gradient-to-r | bg-linear-to-r |
flex-shrink-0 | shrink-0 |
ring (3px by default) | ring-3 (ring is now 1px) |
Version 4 also changed some defaults. Borders now use currentColor instead of a light grey, so a bare border may look darker than the designer expects until you add a colour like border-slate-200. The upgrade guide in the Tailwind docs lists every change; skim it once so these surprises feel familiar.
@tailwind utilities; in the CSS and a tailwind.config.js with a content array. Which version is it most likely using?Upgrading with the official tool
Tailwind ships an upgrade tool that does most of the mechanical work:
npx @tailwindcss/upgradeRun from the project root, it updates the dependencies, moves your JavaScript config into @theme and other CSS directives, swaps the @tailwind lines for the import, and rewrites renamed classes across your templates (so shadow-sm becomes shadow-xs everywhere). It needs a recent version of Node.js (the docs say 20 or newer at the time of writing).
Treat it like any automated refactor. Run it on its own branch, read the whole diff, and click through the app before merging. Two things deserve extra care:
- Browser support. Version 4 relies on modern CSS features such as cascade layers and
@property, and targets Safari 16.4, Chrome 111 and Firefox 128 or newer. If your product must support older browsers, stay on version 3 for now. Check the compatibility page in the docs for the current list. - Large configs with JavaScript logic. If the old config computes values with functions, the tool may not translate everything. Version 4 can still load a legacy file with
@config "./tailwind.config.js";while you migrate piece by piece.
Put a safe version 3 to version 4 upgrade in order.
- Tap the steps below in the right order.
Team conventions that keep Tailwind tidy
Tailwind does not enforce style; your team does. The conventions below show up in most healthy codebases.
Sort classes automatically. The official Prettier plugin, prettier-plugin-tailwindcss, sorts every class list into the same order Tailwind uses in its CSS: layout first, then spacing, then typography, then states and breakpoints. Nobody argues about order in review, and diffs stay small. With version 4, point the plugin at your main stylesheet so it knows your custom tokens:
{
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindStylesheet": "./app/globals.css"
}Extract components, not class names. When a class list repeats, the fix is a React component (or a loop), not a new CSS class. Keep @apply for the rare cases where you cannot touch the markup, such as styling HTML from a CMS. A stylesheet full of .card-header-left { @apply ... } rules is the "old CSS" problem with extra steps.
Arbitrary values need a reason. w-[37rem] to match an embedded map is fine. mt-[13px] because "it looked right" is a smell: it fights the spacing scale and makes the next screen slightly inconsistent. A simple team rule is that if an arbitrary value appears twice, it becomes a token.
Tokens are the single source of truth. Brand colours, fonts and radii live in @theme and nowhere else. Many teams reset the default palette with --color-*: initial; so an off-brand bg-pink-400 simply does not exist. Designers and developers then speak the same words: "use surface and accent", not "use that blue".
Use the editor tooling. The Tailwind CSS IntelliSense extension autocompletes your tokens, shows the CSS on hover and warns about conflicting classes like p-2 p-4 on one element.
The editor catches typos and conflicts while you type, the cheapest moment to fix them.
A review checklist for Tailwind pull requests
When you review a pull request that touches styling, read the classes the way you would read CSS. Here is a checklist you can paste into your team's PR template:
- Tokens, not one-offs. Colours and fonts come from the theme. Arbitrary values have a reason.
- No dynamic class strings. No
`bg-${color}-500`; options are full strings in a map. - Reuse. A repeated class list became a component, and the component accepts
className. - States. Every interactive element has
hover:,focus-visible:and, where relevant,disabled:styles. - Responsive. Mobile-first classes, checked at about 390, 768 and 1280 pixels wide.
- Dark mode. If the app has one, new colours have
dark:partners or use semantic tokens. - Accessibility. Text contrast passes, information is not shown by colour alone, icon buttons have labels, and motion respects
motion-reduce:.
Accessibility checks are where reviews most often catch real bugs, because utility classes make it very easy to pick a pretty grey that nobody can read. Body text needs a contrast ratio of at least 4.5 to 1 against its background. On white, text-slate-500 passes for normal text, while text-slate-400 does not. Chrome DevTools shows the ratio when you click the colour swatch of an element's text, and the axe DevTools extension or Lighthouse will flag failures across a page.
Practice on this card. It has four problems a reviewer should catch:
Preview
The fixes: text-slate-300 fails contrast, so use text-slate-600. The red dot shows "overdue" by colour alone, so add the word Overdue beside it. The "button" is a div, so it cannot be reached with Tab: make it a real <button> with focus-visible: styles. The last line uses an off-scale arbitrary colour and a conflicting mt-[13px] next to mt-3. Make the changes and press Tab in the preview to check.
Performance: why the CSS stays small
Tailwind writes CSS only for the classes it finds in your files. Because a team reuses the same few hundred utilities (flex, p-4, text-sm) across every page, the stylesheet grows very slowly as the app grows. A hand-written stylesheet tends to grow with every feature, since each new component brings new selectors, and old rules are rarely deleted because nobody is sure they are unused. With Tailwind, deleting a component deletes its styles at the next build. Many production apps ship a single CSS file of only a few kilobytes once compressed.
The flip side is HTML size: long class lists repeat in the markup. Compression handles repetition extremely well, so in practice this rarely matters, but it is a fair point to mention when comparing approaches.
Tailwind, CSS Modules or CSS-in-JS?
Interviewers love this comparison, and a balanced answer beats a fan's answer.
| Tailwind | CSS Modules | CSS-in-JS (runtime) | |
|---|---|---|---|
| Where styles live | Classes in the markup | A .module.css file per component | JavaScript, next to the component |
| Scoping | No custom selectors to collide | Class names made unique at build time | Generated unique class names |
| Runtime cost | None, plain CSS | None, plain CSS | Styles created in the browser |
| Design system | Built in through @theme | You build it with variables | Usually a theme object |
| Main cost | Long class lists, learning the names | Switching files, naming things | Extra JavaScript, harder with server components |
Runtime CSS-in-JS libraries like styled-components and Emotion generate styles while the app runs. That costs JavaScript and work in the browser, and it fits poorly with React Server Components, which send no JavaScript for themselves. Zero-runtime options such as vanilla-extract and Panda CSS keep the authoring style but compile to static CSS. CSS Modules remain a solid, simple choice, and many teams mix them with Tailwind.
Match each approach to a fair description.
- tailwind.config.js
- The JavaScript config file used by Tailwind v3 for content paths, theme and plugins.
- @tailwind directives
- The v3 lines
@tailwind base,componentsandutilitiesthat inject Tailwind's layers. - theme.extend
- The v3 config key that adds tokens on top of the defaults instead of replacing them.
- @tailwindcss/upgrade
- The official codemod that migrates a v3 project to v4.
- prettier-plugin-tailwindcss
- The official Prettier plugin that sorts Tailwind classes into a consistent order.
- contrast ratio
- How different text and background colours are in lightness. Body text needs at least 4.5 to 1.
- CSS-in-JS
- Writing styles in JavaScript. Runtime versions generate CSS in the browser; zero-runtime versions compile it at build time.