Toggle navigation
☰
HTML
CSS
Scripting
Database
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tailwind CSS Navbar With Dropdown</title> <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.2.1"></script> </head> <body class="bg-gray-50 h-screen"> <nav class="bg-white border-b border-gray-200" x-data="{ open: false, dropdown: false }"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="flex justify-between h-16"> <div class="flex"> <!-- Logo --> <div class="shrink-0 flex items-center"> <span class="text-xl font-extrabold text-gray-900 tracking-tighter uppercase">Nexus</span> </div> <!-- Desktop Navigation --> <div class="hidden sm:ml-10 sm:flex sm:space-x-8"> <a href="##" class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium">Dashboard</a> <!-- Dropdown Toggle --> <div class="relative inline-flex items-center" @mouseenter="dropdown = true" @mouseleave="dropdown = false"> <button class="text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 text-sm font-medium focus:outline-none"> <span>Solutions</span> <svg class="ml-1 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /> </svg> </button> <!-- Dropdown Menu (Desktop) --> <div x-show="dropdown" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="absolute left-0 top-full mt-0 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50 py-1" style="display: none;" > <a href="##" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Analytics</a> <a href="##" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Engagement</a> <a href="##" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Security</a> <a href="##" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 border-t border-gray-50">Integrations</a> </div> </div> <a href="##" class="text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 text-sm font-medium">Pricing</a> </div> </div> <!-- Mobile Toggler --> <div class="flex items-center sm:hidden"> <button @click="open = !open" class="p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100"> <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" /> </svg> </button> </div> </div> </div> <!-- Mobile Menu --> <div class="sm:hidden" x-show="open" @click.away="open = false"> <div class="pt-2 pb-3 space-y-1"> <a href="##" class="block pl-3 pr-4 py-2 border-l-4 border-indigo-500 bg-indigo-50 text-indigo-700 text-base font-medium">Dashboard</a> <!-- Mobile Dropdown Section --> <div x-data="{ subopen: false }"> <button @click="subopen = !subopen" class="w-full flex justify-between items-center pl-3 pr-4 py-2 border-l-4 border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800 text-base font-medium"> <span>Solutions</span> <svg class="h-4 w-4 transition-transform" :class="{'rotate-180': subopen}" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /> </svg> </button> <div x-show="subopen" class="bg-gray-50 pl-8 pr-4 py-2 space-y-2"> <a href="##" class="block text-sm text-gray-600 hover:text-gray-900">Analytics</a> <a href="##" class="block text-sm text-gray-600 hover:text-gray-900">Engagement</a> <a href="##" class="block text-sm text-gray-600 hover:text-gray-900">Security</a> </div> </div> <a href="##" class="block pl-3 pr-4 py-2 border-l-4 border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800 text-base font-medium">Pricing</a> </div> </div> </nav> <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script> </body> </html>