Ask any question about Tailwind CSS here... and get an instant response.
Post this Question & Answer:
How can I use Tailwind to create a responsive navbar with dropdowns?
Asked on Feb 20, 2026
Answer
To create a responsive navbar with dropdowns using Tailwind CSS, you can utilize its responsive utilities and flexbox classes. Tailwind's utility-first approach allows you to design a navbar that adapts to different screen sizes with ease.
<!-- BEGIN COPY / PASTE -->
<nav class="bg-gray-800 p-4">
<div class="container mx-auto flex justify-between items-center">
<div class="text-white">Brand</div>
<div class="hidden md:flex space-x-4">
<a href="#" class="text-gray-300 hover:text-white">Home</a>
<div class="relative group">
<button class="text-gray-300 hover:text-white">Dropdown</button>
<div class="absolute left-0 mt-2 w-48 bg-white rounded-md shadow-lg opacity-0 group-hover:opacity-100 transition-opacity">
<a href="#" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">Option 1</a>
<a href="#" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">Option 2</a>
</div>
</div>
<a href="#" class="text-gray-300 hover:text-white">Contact</a>
</div>
<button class="md:hidden text-white">Menu</button>
</div>
</nav>
<!-- END COPY / PASTE -->Additional Comment:
- The navbar uses flexbox to align items horizontally and justify content between the brand and menu items.
- Responsive utilities like "hidden md:flex" ensure the menu is hidden on smaller screens and displayed on medium screens and up.
- The dropdown uses a "group" class to handle hover states, showing the dropdown items when the parent is hovered.
- For mobile responsiveness, a button is provided to toggle the menu, which can be further enhanced with JavaScript for interactivity.
Recommended Links:
