Skip to content

Nested Multi-Level Dropdown

Dark navigation bar with a three-level dropdown: flyout submenus on desktop, an inline accordion on mobile, plus hover, click and full keyboard support.

Also known as: multi level dropdown menu, nested dropdown navigation, submenu flyout menu, three level navigation, dropdown with submenus

Nested Multi-Level Dropdown live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A dark navigation bar with a nested multi-level dropdown: the top menu opens below the bar and each submenu flies out to the side, three levels deep. It is written in plain CSS with a small vanilla JavaScript file for hover, click, touch and keyboard control, and suits product catalogs, documentation sites and SaaS headers with deep information architecture.

How it works

The root div.mld-site holds nav.mld-nav (brand link and ul.mld-bar) and a .mld-stage demo area that gives the open menus room in the preview. Every item is an li.mld-item. Items with children get .mld-has-sub and contain a button.mld-toggle followed directly by a ul.mld-menu; deeper menus also carry .mld-menu--sub. Top-level controls use .mld-top, menu entries use .mld-link.

Visibility is driven by ARIA state alone: .mld-toggle[aria-expanded="true"] + .mld-menu is shown, every other menu stays at display: none. From 720px the first menu is positioned under its button and each .mld-menu--sub sits at left: calc(100% + 0.4375rem) next to its parent, with invisible ::before bridges so the pointer can cross the gap. Below 720px the first menu becomes a full-width panel and deeper levels expand inline as an indented accordion with an accent border.

The script initializes every .mld-nav. It toggles aria-expanded on click, opens branches on mouseenter and closes them HOVER_CLOSE_DELAY milliseconds after mouseleave (mouse users on wide screens only), keeps one open branch per level and closes all nested branches with their parent. When a flyout would leave the viewport, place() adds .mld-menu--left so it opens to the left instead. Clicks outside and focus leaving the nav close everything. The demo starts with Products, Software and Integrations open via aria-expanded="true" in the markup; set them to false for a closed start.

Customization

  • --mld-accent on .mld-site: logo, chevrons, focus rings and the inline border on mobile.
  • --mld-bar and --mld-menu-bg: background of the bar and of every menu panel.
  • --mld-menu-width: width of each dropdown and flyout on wide screens.
  • --mld-hover: background of hovered and expanded menu entries.
  • HOVER_CLOSE_DELAY in script.js: raise it to make flyouts more forgiving for diagonal mouse movement.
  • The 720px breakpoint in style.css and in the desktop media query in script.js: change both together to switch to flyouts earlier or later.
  • Remove .mld-stage and the min-height on .mld-site when you place the nav in a real header.

Use cases

  • Large websites: a three-level dropdown organizes many pages in one dark navigation bar
  • Desktop menus: flyout submenus open on hover or click beside the parent menu item
  • Mobile navigation: nested items become an inline accordion on small screens
  • Accessible sites: full keyboard support lets visitors open and close every level

Accessibility

The menu follows the disclosure navigation pattern: real button elements with aria-expanded and aria-controls, real links, and a nav landmark labelled "Main". Tab reaches every control. Arrow Down opens a top menu and focuses its first entry, Arrow Up/Down move inside a menu, Arrow Right opens a submenu, Arrow Left and Escape close the current level and return focus to its button, and Home/End jump to the first or last entry. All controls have a visible :focus-visible outline, and animations are removed with prefers-reduced-motion: reduce.

Usage notes

Every aria-controls value must match a unique id; prefix them when you place two navs on one page.

Nested Multi-Level Dropdown at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Dropdowns
License
Free for personal and commercial use

Questions about this template

Can I use the Nested Multi-Level Dropdown code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Nested Multi-Level Dropdown – free Pure CSS dropdown template
Nested Multi-Level Dropdown · free Pure CSS dropdown template

More Dropdowns

Hover and Focus Dropdown – free Pure CSS dropdown template

Hover and Focus Dropdown

Dark navbar with pure CSS dropdown menus that open on hover and keyboard focus, plus a small vanilla JS layer for Escape, arrow keys and touch taps.

Menu Dropdown Button Variants – free Bootstrap 6 dropdown template

Menu Dropdown Button Variants

Bootstrap 6 Menu dropdowns on buttons: split button with selectable options, drop up, drop end, drop start, headers, icons and dividers.

Notifications Dropdown with User Photos – free Bootstrap 5 dropdown template

Notifications Dropdown with User Photos

Bootstrap 5 navbar bell dropdown listing notifications with user photos, activity icons, times, unread dots and a mark-all-as-read action.

User Account Dropdown – free Bootstrap 5 dropdown template

User Account Dropdown

Bootstrap 5 avatar dropdown with profile header, plan badge, online/away/busy status picker and account menu links for app headers.

Dropdown Menu with Icons – free Tailwind CSS dropdown template

Dropdown Menu with Icons

Accessible Tailwind CSS menu button with icons, grouped items, dividers, shortcut hints, typeahead and full arrow-key navigation.