storieasy-logo

Mastering Tailwind CSS v4 Configuration: A Comprehensive Guide for Developers

milan

Milan Patel

11 May 2025

|

20 min to read

tailwindcss

TailwindCSSv4

TailwindCSS

NextJS

PostCSS

CSS

Learn how to configure Tailwind CSS v4 in a Next.js project with custom breakpoints, color palettes, and fonts. This step-by-step guide helps you build a scalable and maintainable design system using modern CSS variables.

✅ Step 1: Create a Next.js Project

Open your terminal and run the following command to create a new Next.js project:

1npx create-next-app@latest demo

✅ Step 2: Install Tailwind CSS v4

Navigate into the newly created project directory:

1cd demo

Then install Tailwind CSS and PostCSS:

1npm install tailwindcss @tailwindcss/postcss

✅ Step 3: Configure PostCSS

Create or edit the postcss.config.mjs file in your project root and add the following:

1const config = {
2  plugins: ["@tailwindcss/postcss"],
3};
4
5export default config;

✅ Step 4: Import Tailwind CSS

In your global CSS file (usually styles/globals.css), import Tailwind CSS:

1@import 'tailwindcss';

✅ Step 5: Complete Global CSS Setup

In your styles/globals.css, use the following configuration to import Tailwind CSS and define your custom design like breakpoints, colors, and fonts:

1@import 'tailwindcss';
2
3@theme {
4
5// custom breakpoint
6  --breakpoint-xs: 450px;
7  --breakpoint-sm: 640px;
8  --breakpoint-md: 768px;
9  --breakpoint-lg: 1024px;
10  --breakpoint-xl: 1280px;
11  --breakpoint-2xl: 1536px;
12
13
14// custom colors 
15  --color-primary: #171e67;
16  --color-secondary: #3941a2;
17  --color-accent: #d6d5d8;
18  --color-background: #f5f6fa;
19  --color-gold: #ffd700;
20  --color-darkText: #21264b;
21  --color-lightText: #c8ccdc;
22  --color-success: #2ecc71;
23  --color-danger: #e74c3c;
24  --color-white: #ffffff;
25  --color-black: #000000;
26
27// custom fonts
28  --font-serif: 'Times New Roman';
29  --font-mono: 'Courier New';
30}
31

🌟 Using the :root Selector for Global Colors and Fonts in Tailwind CSS

1@import 'tailwindcss';
2
3:root {
4  --breakpoint-xs: 450px;
5  --breakpoint-sm: 640px;
6  --breakpoint-md: 768px;
7  --breakpoint-lg: 1024px;
8  --breakpoint-xl: 1280px;
9  --breakpoint-2xl: 1536px;
10  --color-primary: #171e67;
11  --color-secondary: #3941a2;
12  --color-accent: #d6d5d8;
13  --color-background: #f5f6fa;
14  --color-gold: #ffd700;
15  --color-darkText: #21264b;
16  --color-lightText: #c8ccdc;
17  --color-success: #2ecc71;
18  --color-danger: #e74c3c;
19  --color-white: #ffffff;
20  --color-black: #000000;
21  --font-serif: 'Times New Roman';
22  --font-mono: 'Courier New';
23}
24
25body {
26  background-color: var(--color-background);
27  color: var(--color-lightText);
28  text-decoration-color: var(--color-darkText);
29}

Conclusion

Configuring Tailwind CSS v4 in a Next.js project doesn't require the typical tailwind.config.ts or tailwind.config.js file for customizations like breakpoints, colors, and fonts.

Newsletter

Subscribe to our newsletter and get our latest updates.

Share with your friends: