Tailwind CSS Config Guide: Custom Colors, Fonts and Theme
September 28, 2026 | 10 min read | Tailwind CSS
By Syed · Frontend Engineer & Creator of UITweak
Default Tailwind looks like default Tailwind. The moment a project needs its own identity, brand colors, a distinctive typeface, custom spacing, you reach for the config. This guide shows how to build a complete custom theme in tailwind.config.js (and the v4 CSS-first way), with copy-paste examples for the pieces every real project customizes.
Shortcut: design your theme visually in our free Tailwind Config Generator and export the finished config in one click.
1. Extend, Do Not Replace
The golden rule: put customizations under theme.extend. This addsyour tokens alongside Tailwind's defaults instead of wiping them out:
// tailwind.config.js
module.exports = {
content: ["./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {
colors: {
brand: {
50: "#eef4ff",
100: "#dbe6fe",
500: "#3b5bdb", // primary
600: "#2f4bc4",
900: "#1a2563",
},
},
},
},
};
// Usage: bg-brand-500, text-brand-100, border-brand-600 ...Defining a full 50 to 900 scale gives you the same flexibility as Tailwind's built-in palettes: light tints for backgrounds, saturated mids for actions, dark shades for text.
2. Custom Fonts
Two steps: load the font, then register it:
// 1. Load it (in your CSS or HTML head)
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap");
// 2. Register it
theme: {
extend: {
fontFamily: {
sans: ["Inter", "ui-sans-serif", "system-ui", "sans-serif"],
display: [""Space Grotesk"", "sans-serif"],
},
},
}
// Usage: font-sans (default body), font-display (headings)Tip: keep a display family for headings and sans for body. Two typefaces is a system; five is a mess.
3. Spacing, Breakpoints and Border Radius
theme: {
extend: {
spacing: {
18: "4.5rem", // p-18, m-18, w-18 ...
112: "28rem",
},
borderRadius: {
"4xl": "2rem", // rounded-4xl
},
screens: {
xs: "480px", // min-width breakpoints
"3xl": "1920px",
},
boxShadow: {
soft: "0 8px 30px rgb(0 0 0 / 0.08)",
},
},
}Custom spacing values slot into every spacing utility automatically: p-18, gap-18, w-112. Define the values your design system actually uses and stop guessing with arbitrary values.
4. Custom Animations in the Config
One-off animate-[...] arbitrary values are fine for prototypes, but a design system needs named animations the whole team can reuse:
theme: {
extend: {
keyframes: {
"fade-up": {
"0%": { opacity: "0", transform: "translateY(12px)" },
"100%": { opacity: "1", transform: "translateY(0)" },
},
shimmer: {
"0%": { backgroundPosition: "-200% 0" },
"100%": { backgroundPosition: "200% 0" },
},
},
animation: {
"fade-up": "fade-up 0.5s ease-out both",
shimmer: "shimmer 2.5s linear infinite",
},
},
}
// Usage: animate-fade-up, animate-shimmerThe both fill mode on entrance animations matters: without it, the element flashes visible before the animation starts on slow devices.
5. Dark Mode That Actually Works
Class-based dark mode gives you manual control (a theme toggle) instead of following the OS:
// tailwind.config.js
module.exports = { darkMode: "class", /* ... */ };
// Toggle "dark" on <html> with one line of JS
// Then style both modes explicitly:
<div className="bg-white text-slate-900 dark:bg-slate-900 dark:text-white">
Adapts to the toggle
</div>Discipline tip: whenever you write a color utility, write its dark: counterpart in the same pass. Retrofitting dark mode across hundreds of components is miserable; pairing them from the start is free.
5. Tailwind v4: The CSS-First Way
In v4 there is no config file by default. You define theme tokens directly in CSS with @theme:
/* app.css (Tailwind v4) */
@import "tailwindcss";
@theme {
--color-brand-500: #3b5bdb;
--color-brand-600: #2f4bc4;
--font-display: "Space Grotesk", sans-serif;
--radius-4xl: 2rem;
}
/* Usage is identical: bg-brand-500, font-display, rounded-4xl */Same utilities, no build config. If you are starting a new project in 2026, this is the path to learn.
7. Plugins Worth Installing
Three official plugins cover 90 percent of what teams hand-roll:
- @tailwindcss/typography. Beautiful default styles for CMS and markdown content (
proseclass). Essential if your site renders blog posts or docs from a CMS. - @tailwindcss/forms. Resets form controls to a clean, customizable baseline. Without it you fight browser default styles on every input.
- @tailwindcss/container-queries. Style components based on their container width instead of the viewport. (Covered in depth in our container queries guide.)
// tailwind.config.js
module.exports = {
plugins: [
require("@tailwindcss/typography"),
require("@tailwindcss/forms"),
require("@tailwindcss/container-queries"),
],
};8. Migrating a v3 Config to v4
Upgrading an existing project? The v3 theme.extend values map directly to v4 @theme tokens:
/* v3: tailwind.config.js v4: app.css */
theme: { @import "tailwindcss";
extend: { @theme {
colors: { --color-brand-500: #3b5bdb;
brand: { --> --color-brand-600: #2f4bc4;
500: "#3b5bdb", --font-display: "Space Grotesk", sans-serif;
600: "#2f4bc4", }
},
}, /* utilities stay identical */
fontFamily: {
display: ["Space Grotesk"],
},
},
}The darkMode: "class" setting becomes @custom-variant dark (&:where(.dark, .dark *)); in v4. Migrate one token group at a time and run your visual tests between steps.
9. Config Hygiene Checklist
- Name tokens by purpose.
brand-500beatsprimary-bluewhen the brand color changes to green next year. - Keep the scale small. Five steps per color is plenty for most products. Fifty custom tokens nobody remembers is just noise.
- Document decisions.A comment saying "brand-600: main CTA, AA contrast on white" saves the next developer an hour.
- Purge correctly. Ensure
contentglobs cover every template path, or production CSS will silently miss classes.
Dynamic Class Names Are Invisible to the Scanner
This is the most reported Tailwind bug that is not a bug:
// looks clever, generates nothing
const color = "indigo";
<button className={`bg-${color}-600 hover:bg-${color}-500`}>Save</button>Tailwind scans your source files for complete class-name strings. Template interpolation runs later, in the browser, long after the CSS was built. The scanner never sees bg-indigo-600, so the utility is never generated, in development or in production. The fix is a lookup map with full class names:
const variants = {
primary: "bg-indigo-600 hover:bg-indigo-500 text-white",
danger: "bg-red-600 hover:bg-red-500 text-white",
};
<button className={variants[variant]}>Save</button>Every string the scanner needs is present verbatim. Tailwind v4's automatic content detection does not change this: it finds more files on its own, but it still cannot execute your JavaScript. If a class is constructed at runtime, it does not exist as far as the build is concerned.
Safelisting: v3 safelist vs v4 @source inline
Some class names genuinely cannot appear in source: CMS-driven content, user-configured themes, classes stored in a database. For those, safelist explicitly. In v3, the config takes a safelist:
// tailwind.config.js
module.exports = {
safelist: [
"bg-red-500",
{ pattern: /^bg-(red|amber|green)-(100|500|900)$/ },
],
};In v4, safelisting moved into CSS with @source inline:
@import "tailwindcss";
@source inline("bg-red-500");
@source inline("bg-amber-100");Two warnings from experience. First, regex patterns bloat your CSS fast: one loose pattern can generate hundreds of utilities nobody uses. Prefer explicit lists. Second, I treat every safelist entry as a smell. If the class can live in source, it should. Safelists are for content that is truly dynamic, not for avoiding a lookup map.
v4 Ignores Gitignored Files
Tailwind v4 finds content automatically, and it respects your .gitignore while doing it. That is usually what you want, until it is not. Generated templates, vendored component libraries, and build outputs that are gitignored will not be scanned, and their utilities will be silently missing from your CSS.
The symptom is maddening: the class is right there in the markup, the dev server is running, and the style does not apply. The fix is an explicit source directive:
@import "tailwindcss";
@source "../shared/templates";
@source not "../shared/templates/legacy";@source registers a path by hand; @source not excludes one. I add explicit @source lines for every template directory outside the project root, especially in monorepos where the UI package lives next to the app. If utilities work in one package and vanish in another, check the gitignore first.
Custom Utilities Belong in @utility
A hand-written CSS class cannot be combined with variants. hover:my-class does nothing, because Tailwind only applies variant prefixes to utilities it generated. In v4, the @utility directive registers your custom CSS as a real utility:
@utility scrollbar-none {
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}Now scrollbar-none works, and so do hover:scrollbar-none, md:scrollbar-none, and every other variant, because Tailwind treats it like any built-in. In v3 the equivalent was @layer utilities plus opting into variants, which most people got wrong. My rule: if a custom class needs to compose with hover:, dark:, or responsive prefixes, it goes in @utility. If it never needs a variant, plain CSS is fine.
Verify Custom Tokens in the Production Build
Dev builds and production builds run the same scanner, but production is where missing content paths and safelist gaps surface. Before shipping a theme change, build for production and check the output CSS actually contains your utilities. The fastest check is searching the built CSS file for the utility selector itself, like bg-brand-500. If the selector is absent, the class was never generated. I run this check on every theme change. It catches gitignored template directories, dynamic class names, and typo'd @source paths in seconds, long before a user reports an unstyled page.
FAQ
Should new projects use v3 config or v4 CSS-first?
v4 CSS-first. It removes a build step, keeps tokens next to the styles that use them, and is where all new Tailwind development happens. Only stay on v3 if a plugin you depend on has no v4 equivalent yet.
Why are my custom colors not working in production?
Almost always the content globs. If a template path is missing fromcontent, Tailwind never sees the classes used there and skips them in the production build. Check every directory that contains markup.
How many custom colors should I define?
One brand scale (5 to 9 steps) plus neutrals covers most products. Every extra palette is a decision every designer and developer has to make forever. Restraint is a feature.
Can I use CSS variables with Tailwind theme tokens?
Yes, and v4 makes it natural: define --color-brand-500 in @theme and reference var(--color-brand-500) in custom CSS. For runtime theming (user-picked colors), point the token at a variable: --color-brand-500: var(--user-accent).
Design your theme visually
Pick colors, fonts, spacing, and dark mode on a live preview, then export a finished tailwind.config.js or v4 CSS.
Open the Config Generator, it's free