Skip to content

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.

20 min read0/4 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")],
};

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.
  • content lists the files Tailwind scans for class names. Version 4 finds your source files automatically and uses @source for anything extra. If a class "does nothing" in a version 3 app, check whether its file matches the content globs first.
  • theme.extend adds tokens on top of the defaults, so brand.600 becomes bg-brand-600. Writing directly under theme (without extend) replaces a whole group, which is the version 3 equivalent of --color-*: initial.
  • darkMode: "class" makes dark: follow a .dark class. In version 4 that is the @custom-variant line.
  • plugins loads extensions. In version 4 it is @plugin in CSS.

A few class names also changed between versions, which trips people up when copying code from old tutorials or Stack Overflow answers:

Version 3Version 4
shadow-sm / shadowshadow-xs / shadow-sm
rounded-sm / roundedrounded-xs / rounded-sm
outline-noneoutline-hidden
bg-opacity-50bg-black/50 (opacity modifier)
bg-gradient-to-rbg-linear-to-r
flex-shrink-0shrink-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.

Quick check
You open a project and find @tailwind utilities; in the CSS and a tailwind.config.js with a content array. Which version is it most likely using?
Need a nudge? A hint rules out a wrong answer.

Upgrading with the official tool

Tailwind ships an upgrade tool that does most of the mechanical work:

npx @tailwindcss/upgrade

Run 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 it in order6 steps

Put a safe version 3 to version 4 upgrade in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

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.

Guardrails from keyboard to merge
Developer: writes classesDeveloperwrites classesIntelliSense: autocomplete, lintIntelliSenseautocomplete, lintPrettier: sorts classesPrettiersorts classesCI: build, lint, a11yCIbuild, lint, a11yReview: checklistReviewchecklistmain: mergedmainmergedtypingsavepushgreenapprove

The editor catches typos and conflicts while you type, the cheapest moment to fix them.

1/4

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:

  1. Tokens, not one-offs. Colours and fonts come from the theme. Arbitrary values have a reason.
  2. No dynamic class strings. No `bg-${color}-500`; options are full strings in a map.
  3. Reuse. A repeated class list became a component, and the component accepts className.
  4. States. Every interactive element has hover:, focus-visible: and, where relevant, disabled: styles.
  5. Responsive. Mobile-first classes, checked at about 390, 768 and 1280 pixels wide.
  6. Dark mode. If the app has one, new colours have dark: partners or use semantic tokens.
  7. 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:

HTML + Tailwind
<div class="max-w-sm rounded-xl border border-slate-200 p-5"> <h3 class="text-lg font-semibold">Invoice #2041</h3> <p class="mt-1 text-sm text-slate-300">Due in 3 days</p> <p class="mt-3 flex items-center gap-2 text-sm"> <span class="size-2.5 rounded-full bg-red-500"></span> </p> <div onclick="this.textContent = 'Paid'" class="mt-4 inline-block cursor-pointer rounded-lg bg-indigo-600 px-4 py-2 text-white">Pay now</div> <p class="mt-3 text-sm text-[#7c7cff] mt-[13px]">Need help?</p></div>

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.

Quick check
Which of these pull request changes should a reviewer push back on?
Need a nudge? A hint rules out a wrong answer.

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.

TailwindCSS ModulesCSS-in-JS (runtime)
Where styles liveClasses in the markupA .module.css file per componentJavaScript, next to the component
ScopingNo custom selectors to collideClass names made unique at build timeGenerated unique class names
Runtime costNone, plain CSSNone, plain CSSStyles created in the browser
Design systemBuilt in through @themeYou build it with variablesUsually a theme object
Main costLong class lists, learning the namesSwitching files, naming thingsExtra 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 the pairs0/4 matched

Match each approach to a fair description.

Choose an item, then its match on the other side.
Key terms
tailwind.config.js
The JavaScript config file used by Tailwind v3 for content paths, theme and plugins.
@tailwind directives
The v3 lines @tailwind base, components and utilities that 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.