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 Sidebar With Nested Menu</title> <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.2.1"></script> </head> <body class="bg-gray-100 flex min-h-screen"> <aside class="w-64 bg-slate-900 text-slate-300 flex flex-col" x-data="{ openSub: false }"> <div class="px-6 py-8"> <div class="text-white font-black text-xl tracking-tight">TREE.NAV</div> </div> <nav class="flex-1 px-4 space-y-1"> <a href="##" class="block px-4 py-2 rounded-lg hover:bg-slate-800 transition-colors">Dashboard</a> <!-- Nested Toggle --> <div> <button @click="openSub = !openSub" class="w-full flex items-center justify-between px-4 py-2 rounded-lg hover:bg-slate-800 transition-colors focus:outline-none" > <span>Projects</span> <svg class="h-4 w-4 transition-transform duration-200" :class="{'rotate-180': openSub}" 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="openSub" x-transition class="mt-1 ml-4 border-l border-slate-700 pl-4 space-y-1" style="display: none;"> <a href="##" class="block py-2 text-sm text-slate-400 hover:text-white transition-colors">Web Redesign</a> <a href="##" class="block py-2 text-sm text-slate-400 hover:text-white transition-colors">Mobile App</a> <a href="##" class="block py-2 text-sm text-slate-400 hover:text-white transition-colors">Marketing Site</a> </div> </div> <a href="##" class="block px-4 py-2 rounded-lg hover:bg-slate-800 transition-colors">Employees</a> <a href="##" class="block px-4 py-2 rounded-lg hover:bg-slate-800 transition-colors">Settings</a> </nav> </aside> <main class="flex-1 p-10 bg-white shadow-inner"> <h1 class="text-2xl font-bold text-slate-800">Hierarchical Sidebar</h1> <p class="mt-4 text-slate-600">Nested menus are useful for organizing content into logical groups without cluttering the main navigation view.</p> </main> <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script> </body> </html>