Now that you have Tailwind CSS installed and working, itβs time to build something real.
In this post, weβll create a responsive navbar using Tailwind CSS in a Next.js project.
This is one of the most common UI components used in almost every website.
π§± Step 1: Basic Navbar Structure
Letβs start with a simple navbar layout:
export default function Navbar() {
return (
<nav className="bg-white shadow-md">
<div className="max-w-6xl mx-auto px-4">
<div className="flex justify-between items-center h-16">
{/* Logo */}
<div className="text-xl font-bold text-blue-600">
MyBrand
</div>
{/* Desktop Menu */}
<div className="hidden md:flex space-x-6">
<a href="#" className="text-gray-700 hover:text-blue-600">Home</a>
<a href="#" className="text-gray-700 hover:text-blue-600">About</a>
<a href="#" className="text-gray-700 hover:text-blue-600">Services</a>
<a href="#" className="text-gray-700 hover:text-blue-600">Contact</a>
</div>
</div>
</div>
</nav>
);
}π± Step 2: Add Mobile Menu Button
Now weβll make it responsive by adding a mobile menu button.
Add state handling:
import { useState } from "react";export default function Navbar() {
const [isOpen, setIsOpen] = useState(false);
return (
<nav className="bg-white shadow-md">
<div className="max-w-6xl mx-auto px-4">
<div className="flex justify-between items-center h-16">
<div className="text-xl font-bold text-blue-600">
MyBrand
</div>
{/* Desktop Menu */}
<div className="hidden md:flex space-x-6">
<a href="#" className="text-gray-700 hover:text-blue-600">Home</a>
<a href="#" className="text-gray-700 hover:text-blue-600">About</a>
<a href="#" className="text-gray-700 hover:text-blue-600">Services</a>
<a href="#" className="text-gray-700 hover:text-blue-600">Contact</a>
</div>
{/* Mobile Button */}
<button
className="md:hidden text-gray-700"
onClick={() => setIsOpen(!isOpen)}
>
β°
</button>
</div>
{/* Mobile Menu */}
{isOpen && (
<div className="md:hidden flex flex-col space-y-2 pb-4">
<a href="#" className="text-gray-700">Home</a>
<a href="#" className="text-gray-700">About</a>
<a href="#" className="text-gray-700">Services</a>
<a href="#" className="text-gray-700">Contact</a>
</div>
)}
</div>
</nav>
);
}π― Step 3: Understanding the Responsive Logic
Letβs break it down:
πΉ Desktop Menu
hidden md:flex
hidden β hide on mobile
md:flex β show on medium screens and above
πΉ Mobile Menu Button
md:hidden
visible only on small screens
disappears on desktop
πΉ Mobile Menu Toggle
We use:
const [isOpen, setIsOpen] = useState(false);This allows us to:
π Show / hide menu dynamically
π¨ Step 4: Improve UI (Optional Enhancement)
You can make it more modern by adding:
β Hover animations
β Smooth transitions
β Better spacing
β Icons instead of β°
Example enhancement:
className="text-gray-700 hover:text-blue-600 transition duration-200"β‘ What You Just Built
You now have:
β Responsive Navbar
β Mobile menu toggle
β Clean Tailwind utility structure
β Real-world Next.js component
This is exactly how production UIs are built.
π§ Key Learning
Tailwind makes responsive design simple using:
sm:
md:
lg:
xl:
Instead of writing media queries manually, you control everything inside classes.
π Whatβs Next?
In the next post, weβll build:
π Hero Section with Tailwind CSS (Modern Landing Page UI)
This is where your UI starts looking like real SaaS websites.



