CSS Multi-level Dropdown

A nested dropdown where submenus fly out to the side on hover or focus, built from plain nested lists.

  • dropdown
  • submenu
  • flyout
  • nested
  • focus-within
  • hover
HTML
<nav class="multi-menu" aria-label="Main">
  <ul>
    <li>
      <a href="#">Services</a>
      <ul>
        <li><a href="#">Design</a></li>
        <li>
          <a href="#">Development</a>
          <ul>
            <li><a href="#">Web apps</a></li>
            <li><a href="#">Mobile</a></li>
          </ul>
        </li>
        <li><a href="#">Hosting</a></li>
      </ul>
    </li>
  </ul>
</nav>
CSS
.multi-menu ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.multi-menu li {
  position: relative;
}

.multi-menu a {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #0f172a;
  font: 500 14px system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
}

/* Arrow on items that have a submenu */
.multi-menu li:has(> ul) > a::after {
  content: "›";
  color: #94a3b8;
}

.multi-menu > ul > li > a::after {
  transform: rotate(90deg);
}

.multi-menu li ul {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  min-width: 150px;
  padding: 6px;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 0 0 1px #0f172a14, 0 12px 28px -8px #0f172a40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s;
}

/* Third level flies out to the right */
.multi-menu li li ul {
  top: -6px;
  left: 100%;
}

.multi-menu li:hover > ul,
.multi-menu li:focus-within > ul {
  opacity: 1;
  visibility: visible;
}

.multi-menu a:hover,
.multi-menu li:focus-within > a {
  background: #f1f5f9;
}

.multi-menu a:focus-visible {
  outline: 2px solid #0891b2;
  outline-offset: -2px;
}

About this CSS Multi-level Dropdown

This CSS Multi-level Dropdown is 68 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and Flexbox. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #0f172a
  • #94a3b8
  • #ffffff
  • #0f172a14
  • #0f172a40
  • #f1f5f9
  • #0891b2

How to use this multi-level dropdown

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .multi-menu class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback