Scroll Top

Nextjs 14 Tailwind 4 Config Example & A Detailed Guide for Devs.

how-to-set-up-tailwind-css-v4-with-nextjs

This article is aimed at developers who already have a basic understanding of React and Next.js, as well as some familiarity with CSS. In this article, we’ll walk you through nextjs 14 Tailwind config, highlight the benefits of this combination, and demonstrate how Tailwind Nextjs can work together to build fast, responsive, and scalable web applications. You can even consider this guide for the Tailwind config nextjs 14 app.

What You Need for Tailwind Nextjs Integration

Before we dive in, here’s what you’ll need:

  • Node.js: Both TailwindCSS and Next.js require Node.js. You can check if it’s installed by running node -v in your terminal.
  • Basic Understanding of JavaScript and React: Familiarity with JavaScript and React is important since Next.js is built on React.
  • Familiarity with Next.js: While it’s helpful to know the basics of Next.js, don’t worry if you’re still getting familiar with it—this guide will walk you through the setup process.

Why Choose Tailwind Nextjs Combo?

When you combine Tailwind with Nextjs, you get a powerful combination for building fast, scalable websites. Next.js provides performance optimizations like server-side rendering (SSR) and static site generation (SSG), while TailwindCSS allows you to design directly in your HTML using utility classes.

Benefits of Using TailwindCSS with Next.js:

  • Faster Development: Tailwind’s utility-first approach allows for rapid development, while Next.js provides optimizations like SSR and SSG to enhance performance.
  • Better Developer Experience: Next.js features like fast refresh, routing, and simple API creation, combined with Tailwind’s responsive utilities, make for a smooth and efficient workflow.
  • Scalability: Both TailwindCSS and Next.js are built to handle large projects with ease, ensuring that your website can grow as your needs evolve.

Together, these tools streamline both development and performance, making them an excellent choice for modern web applications.


Check out the best nextjs template for responsive and fast web apps.

Materio React Free Admin Template

This is one of the best free vercel theme you can consider for your vercel projects.


Step-by-Step Guide to Setting Up TailwindCSS v4 with Next.js

Now that we’ve explored why Tailwind CSS and Next.js make a powerful combination, it’s time to dive into the process of setting them up together. Let’s walk through the steps to integrate Tailwind CSS with Next.js and get your project up and running smoothly.

Create A new Next.js Project:

First, let’s start by setting up a new Next.js project. Head to your terminal and type the following command:

npx create-next-app my-project
cd my-project

Install Tailwind CSS

In your Next.js project, install Tailwind CSS and its required dependencies by running the command for @tailwindcss/postcss via npm.

npm install tailwindcss @tailwindcss/postcss postcss

This will generate a postcss.config.js file in the root directory of your project.

Configure PostCSS Plugins

In the root directory of your project, create a postcss.config.mjs file and include the @tailwindcss/postcss plugin in your PostCSS setup.

const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};
export default config;

Import Tailwind CSS

In the ./src/app/globals.css file, add a @import statement that includes Tailwind CSS.

@import "tailwindcss";

Run the Development Server

Next, launch the development server to see Tailwind CSS in action:

npm run dev

Your Next.js project is now successfully integrated with Tailwind CSS. You can start using Tailwind’s utility classes to style your components.

Creating a Profile Card Using TailwindCSS Utilities

Create a new file named ProfileCard.tsx for the component.

Create a ProfileCard.tsx file inside the /src/components directory of your project.

import Image from "next/image";

export default function ProfileCard() { 
	return (
		<div className="flex flex-col items-center justify-center max-w-md p-6 bg-white rounded-lg shadow-md gap-4 text-center">
			<Image src="/avatar.png" alt="user" width="50" height="50" className="rounded-full"/>
			<div className="flex flex-col items-center">
				<h2 className="text-xl font-semibold">John Doe</h2>
				<p className="text-gray-500">Software Engineer</p>
			</div>
			<div className="flex gap-2">
				<div className="flex flex-col items-center px-4">
					<span className="text-lg font-semibold">120</span>
					<span className="text-gray-500">Posts</span>
				</div>
				<div className="flex flex-col items-center px-4">
					<span className="text-lg font-semibold">80k</span>
					<span className="text-gray-500">Following</span>
				</div>
				<div className="flex flex-col items-center px-4">
					<span className="text-lg font-semibold">1.2K</span>
					<span className="text-gray-500">Following</span>
				</div>
			</div>
			<p className="text-gray-500">
				Lorem, ipsum dolor sit amet consectetur adipisicing elit. Harum animi beatae molestiae quasi fugiat ut.
			</p>
			<button className="bg-purple-400 text-white px-6 py-3 rounded-full hover:bg-purple-500 transition duration-300 active:scale-95">
				View Profile
			</button>
		</div>
	);
}

Bring the ProfileCard component into the file where you want to use it

Currently, we are importing it into the /src/app/page.tsx file.

import ProfileCard from "@/components/ProfileCard";

export default function Home() {
  return (
    <div className="flex h-screen justify-center items-center"><ProfileCard/></div>
  );
}

Run the Development Server

Start the development server to view your ProfileCard In action.

npm run dev

Then, open your browser and navigate to http://localhost:3000/ to see the result.

Creating a Profile Card with TailwindCSS and FlyonUI

What is Flyon UI?

Flyon UI Tailwind Components Library

FlyonUI is the free Tailwind Components Library designed to combine the best of both worlds: the aesthetic appeal of semantic classes and the powerful functionality of JS plugins.

Under the hood, it uses the strengths of:

  • Tailwind CSS: A utility-first CSS framework that helps you build beautiful websites with ease.
  • DaisyUI: adds component semantic class names to Tailwind CSS so you can make beautiful websites faster, easier, and more Maintainable.
  • Preline: JavaScript headless & fully unstyled Tailwind plugins for accessible, responsive UI. Enhance experiences with animations, transitions, and more.

Features:

  • JS plugins Support
  • Semantic Components
  • 800+ Free Components Examples
  • Universal Framework Compatibility
  • Unlimited Themes
  • Unstyled & Accessible Plugins
  • Responsive & RTL support
  • Free Forever
  • Beautiful and Semantic Styling
  • Efficiency and Productivity
  • Maintainable and Scalable

Also available in pro version. It includes,

Check out the most blazing-fast Tailwind AI Builder – FlyonUI MCP. Craft stunning UI Components, Landing Pages, Blocks, Sections, and much more within seconds by simply providing prompts.

flyonui mcp ad banner 1

Install FlyonUI

First, add FlyonUI – Tailwind UI components as a dependency to your project by executing this command:

npm install flyonui

Add the FlyonUI plugin

Add the FlyonUI plugin to your global.css file.

@plugin "flyonui";
@import "flyonui/variants.css";
@source "./node_modules/flyonui/flyonui.js"; // Add only if node_modules is gitignored

Create FlyonUI JavaScript loader

Create a FlyonuiScript.tsx file in your project, for example, under src/components/.

'use client';

import { usePathname } from 'next/navigation';
import { useEffect } from 'react';

import { IStaticMethods } from 'flyonui/flyonui';
declare global {
  interface Window {
    HSStaticMethods: IStaticMethods;
  }
}

async function loadFlyonUI() {
  return import('flyonui/flyonui');
}

export default function FlyonuiScript() {
  const path = usePathname();

  useEffect(() => {
    const initFlyonUI = async () => {
      await loadFlyonUI();
    };

    initFlyonUI();
  }, []);

  useEffect(() => {
    setTimeout(() => {
      if (
        window.HSStaticMethods &&
        typeof window.HSStaticMethods.autoInit === 'function'
      ) {
        window.HSStaticMethods.autoInit();
      }
    }, 100);
  }, [path]);

  return null;
}

Add the FlyonUI JavaScript loader

Incorporate the FlyonUI JavaScript loader into your app’s entry point, such as root_directory/app/layout.tsx.

...

import FlyonuiScript from '../components/FlyonuiScript';

...

export default function RootLayout({ children, }: { children: React.ReactNode; }) {
  return (
    <html>
      ...
      <body>
        ...
        <FlyonuiScript />
      </body>
    </html>
  );
}

FlyonUI is also available in pro version. It includes

Refactor the ProfileCard by integrating FlyonUI components

Let’s utilize FlyonUI components like Avatar, Card, and Button, which are pre-styled and help save a lot of development time.

export default function ProfileCard() { 
	return (
			<div className="card sm:max-w-sm">
				<div className="card-body items-center text-center gap-4">
					<div className="avatar">
						<div className="size-14 rounded-full">
							<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-1.png" alt="avatar" />
						</div>
					</div>
					<div className="flex flex-col items-center">
						<h2 className="text-xl font-semibold text-base-content">John Doe</h2>
						<p className="text-gray-500">Software Engineer</p>
					</div>
					<div className="flex gap-2">
						<div className="flex flex-col items-center px-4">
							<span className="text-lg font-semibold text-base-content">120</span>
							<span className="text-gray-500">Posts</span>
						</div>
						<div className="flex flex-col items-center px-4">
							<span className="text-lg font-semibold text-base-content">80k</span>
							<span className="text-gray-500">Following</span>
						</div>
						<div className="flex flex-col items-center px-4">
							<span className="text-lg font-semibold text-base-content">1.2K</span>
							<span className="text-gray-500">Following</span>
						</div>
					</div>
					<p>
						Lorem, ipsum dolor sit amet consectetur adipisicing elit. Harum animi beatae molestiae quasi fugiat ut.
					</p>

					<div className="card-actions">
						<button className="btn btn-primary rounded-full">View Profile</button>
					</div>
				</div>
			</div>
	);
}

This is how your Profile Card will appear.

Tailwind nextjs cofig

Conclusion

Integrating TailwindCSS with Next.js is a powerful combination that enhances both the development experience and the performance of your web applications. Tailwind’s utility-first approach streamlines styling, while Next.js provides excellent performance optimizations like server-side rendering and static site generation. Together, they allow you to build fast, responsive, and scalable web apps with ease.

By incorporating tools like FlyonUI, you can further accelerate your development process with pre-styled components, saving both time and effort. Whether you’re working on a personal project or a large-scale application, this setup ensures that you have all the resources you need to create a modern, efficient, and customizable web app.

If you are looking for best Tailwind Resources, check out the best collective at

Happy coding!

Related Posts

close-link
Register to ThemeSelection 🚀

Prefer to Login/Register with:

OR
Already Have Account?

By Signin or Signup to ThemeSelection.com using social accounts or login/register form, You are agreeing to our Terms & Conditions and Privacy Policy
close-link
Reset Your Password 🔐

Enter your username/email address, we will send you reset password link on it. 🔓

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.