Master Code
On The Go

Learn. Practice. Build.

Home › How-To › Tailwind Config Guide

Tailwind CSS Guide

Tailwind CSS Config Guide

Customize your theme in CSS using the new @theme directive in v4.

Last updated: October 2026 · Tested on Tailwind v4.0

Quick answer: In Tailwind v4, there is no tailwind.config.js. All configuration lives in your CSS file inside the @theme directive. Define custom colors with --color-brand: #3b82f6;, fonts with --font-display: "Inter";, and spacing with --spacing-128: 32rem;. Tailwind generates utility classes for each.

1

Why v4 Changed Everything

In Tailwind v3, you configured the framework in a JavaScript file:

// tailwind.config.js (v3 — no longer needed)
module.exports = {
    theme: {
        extend: {
            colors: {
                brand: '#3b82f6'
            }
        }
    }
}

In v4, that same config lives directly in CSS:

@import "tailwindcss";

@theme {
    --color-brand: #3b82f6;
}

Same result, less friction. Your theme values are now real CSS variables you can use anywhere.

2

Custom Colors

@theme {
    --color-brand: #3b82f6;
    --color-brand-light: #93c5fd;
    --color-brand-dark: #1e40af;
    --color-accent: oklch(0.7 0.2 340);
}

Now you can use these anywhere:

<button class="bg-brand hover:bg-brand-dark text-white">
    Button
</button>
<p class="text-brand-light">Subtle text</p>

💡 Naming tip: Use semantic names (brand, danger, success) instead of color descriptions (blue, red). This makes redesigns easy — change the value in one place.

3

Custom Fonts

@theme {
    --font-display: "Inter", sans-serif;
    --font-mono: "JetBrains Mono", monospace;
}

Use them with font-display and font-mono:

<h1 class="font-display text-4xl">Heading</h1>
<code class="font-mono text-sm">const x = 1;</code>
4

Custom Spacing

@theme {
    --spacing-18: 4.5rem;
    --spacing-128: 32rem;
    --spacing-200: 50rem;
}

Now p-18, m-128, and w-200 all work. This is especially useful for custom container widths and vertical rhythm.

5

Custom Breakpoints

@theme {
    --breakpoint-xs: 30rem;
    --breakpoint-3xl: 120rem;
}

Now you can use xs: and 3xl: prefixes just like the built-in md: and lg::

<div class="grid grid-cols-1 xs:grid-cols-2 md:grid-cols-3 3xl:grid-cols-6">
    ...
</div>
6

Custom Animations

@theme {
    --animate-fade-in: fade-in 0.3s ease-out;
    --animate-slide-up: slide-up 0.4s ease-out;

    @keyframes fade-in {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    @keyframes slide-up {
        from { transform: translateY(20px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
}

Use them with the animate- prefix:

<div class="animate-fade-in">Fades in</div>
<div class="animate-slide-up">Slides up</div>

🔍 The Complete @theme Reference

What you want CSS variable prefix
Colors --color-*
Font families --font-*
Font sizes --text-*
Spacing --spacing-*
Breakpoints --breakpoint-*
Border radius --radius-*
Shadows --shadow-*
Animations --animate-*

🛡️ Best Practices

Migrating from v3? The upgrade is not automatic. Use the official tool: npx @tailwindcss/upgrade. It converts your tailwind.config.js to a v4 CSS config, but always review the output.

❓ Frequently Asked Questions

How do I configure Tailwind CSS v4?

In Tailwind v4, configuration happens in CSS using the @theme directive. You no longer need a tailwind.config.js file. Add @theme { --color-brand: #3b82f6; } to your CSS to define custom colors.

Does Tailwind v4 still need tailwind.config.js?;

No. Tailwind v4 eliminates the JavaScript config file entirely. All theme customization is done in CSS using @theme. This includes colors, fonts, spacing, breakpoints, and animations.

How do I add custom colors to Tailwind?

In Tailwind v4, add --color-yourname: #hexvalue; inside @theme in your CSS file. Then use it as bg-yourname, text-yourname, or border-yourname.

How do I customize Tailwind breakpoints?

Add --breakpoint-name: value; inside @theme. For example, --breakpoint-3xl: 120rem; creates a new 3xl: prefix you can use in your classes.

Can I still use tailwind.config.js in v4?

You can use the @config directive to load a legacy config file, but it is not recommended. The CSS-first approach with @theme is faster and integrates better with the rest of your CSS.

🎯 What's Next?

← All How-To Guides