Component
Multi Level Menu
Nested dropdown menu with three levels of submenus for e-commerce category navigation.
- Component
- Tailwind
- HTML
- MIT
Preview
Live component
9:41 100%
devsnips.dev/library/tailwind/components/dropdowns/multi-level-menu/ fluid · no fixed width 100%
Install
Add to your project
npx devsnips add Tailwind/Components/Dropdowns/multi-level-menu Tailwind/Components/Dropdowns/multi-level-menu <!-- Multi Level Menu -->
<div class="relative inline-block">
<button
id="multi-level-button"
class="inline-flex items-center gap-2 px-4 py-2.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors"
onclick="toggleDropdown('multi-level-menu')"
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h7"></path>
</svg>
<span>Browse Categories</span>
<svg class="w-4 h-4 transition-transform" id="multi-level-arrow" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
</svg>
</button>
<!-- Level 1 Menu -->
<div
id="multi-level-menu"
class="hidden absolute left-0 z-20 mt-2 w-64 bg-white rounded-xl shadow-xl border border-gray-200 overflow-hidden"
>
<div class="py-2">
<!-- Level 1 Item with Submenu -->
<div class="relative level-1-item">
<button class="w-full flex items-center justify-between px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 transition-colors">
<div class="flex items-center gap-3">
<svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
</svg>
<span>Electronics</span>
</div>
<svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</button>
<!-- Level 2 Submenu -->
<div class="hidden level-2-menu absolute left-full top-0 w-56 bg-white rounded-xl shadow-xl border border-gray-200 ml-1">
<div class="py-2">
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Computers</span>
</a>
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Phones</span>
</a>
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Tablets</span>
</a>
<!-- Level 2 Item with Submenu -->
<div class="relative level-2-item">
<button class="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 transition-colors">
<div class="flex items-center gap-3">
<span>Accessories</span>
</div>
<svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</button>
<!-- Level 3 Submenu -->
<div class="hidden level-3-menu absolute left-full top-0 w-48 bg-white rounded-xl shadow-xl border border-gray-200 ml-1">
<div class="py-2">
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
Headphones
</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
Chargers
</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
Cases
</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
Cables
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Level 1 Item -->
<a href="#" class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<svg class="w-5 h-5 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z"></path>
</svg>
<span>Clothing & Fashion</span>
</a>
<!-- Level 1 Item -->
<a href="#" class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<svg class="w-5 h-5 text-amber-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3"></path>
</svg>
<span>Home & Garden</span>
</a>
<!-- Level 1 Item -->
<a href="#" class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<svg class="w-5 h-5 text-emerald-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path>
</svg>
<span>Books & Media</span>
</a>
<!-- Level 1 Item -->
<a href="#" class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<svg class="w-5 h-5 text-rose-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
</svg>
<span>Health & Beauty</span>
</a>
<!-- Level 1 Item with Submenu -->
<div class="relative level-1-item">
<button class="w-full flex items-center justify-between px-4 py-2.5 text-sm text-gray-700 hover:bg-blue-50 transition-colors">
<div class="flex items-center gap-3">
<svg class="w-5 h-5 text-cyan-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>Sports & Outdoors</span>
</div>
<svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</button>
<!-- Level 2 Submenu -->
<div class="hidden level-2-menu absolute left-full top-0 w-56 bg-white rounded-xl shadow-xl border border-gray-200 ml-1">
<div class="py-2">
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Team Sports</span>
</a>
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Outdoor Activities</span>
</a>
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Fitness Equipment</span>
</a>
<a href="#" class="flex items-center gap-3 px-4 py-2 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors">
<span>Camping & Hiking</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function toggleDropdown(id) {
const menu = document.getElementById(id);
const arrow = document.getElementById('multi-level-arrow');
menu.classList.toggle('hidden');
arrow.classList.toggle('rotate-180');
}
// Multi-level hover functionality
document.querySelectorAll('.level-1-item').forEach(item => {
item.addEventListener('mouseenter', function() {
const submenu = this.querySelector('.level-2-menu');
if (submenu) {
submenu.classList.remove('hidden');
}
});
item.addEventListener('mouseleave', function() {
const submenu = this.querySelector('.level-2-menu');
if (submenu) {
submenu.classList.add('hidden');
}
});
});
document.querySelectorAll('.level-2-item').forEach(item => {
item.addEventListener('mouseenter', function() {
const submenu = this.querySelector('.level-3-menu');
if (submenu) {
submenu.classList.remove('hidden');
}
});
item.addEventListener('mouseleave', function() {
const submenu = this.querySelector('.level-3-menu');
if (submenu) {
submenu.classList.add('hidden');
}
});
});
document.addEventListener('click', function(event) {
const container = document.querySelector('.relative.inline-block');
const button = document.getElementById('multi-level-button');
const menu = document.getElementById('multi-level-menu');
if (!container.contains(event.target)) {
menu.classList.add('hidden');
document.getElementById('multi-level-arrow').classList.remove('rotate-180');
}
});
</script> # Multi Level Menu
Nested multi-level dropdown menu.
## Preview
Open `preview.html` for a standalone demonstration.
## Features
- Nested submenus
- Hierarchical navigation
## Usage
```bash
npx devsnips add Tailwind/Components/Dropdowns/multi-level-menu
```
Copy from `code.html`.
## Customization
- Submenu positioning and styles
## Accessibility
- Submenu open/close must be keyboard operable
## Dependencies
- Tailwind CSS; JS as present
## File Structure
- `code.html` · `preview.html` · `metadata.json` · `README.md` 199 lines UTF-8 · LF · Spaces: 2
Continue browsing