Build a dropdown menu with HTML and CSS
For a dropdown navigation without JavaScript, put a <summary> first inside <details>, followed by the list of links. The browser opens and closes the list, while CSS controls where it appears and how it looks.
Build the disclosure in HTML
Without the open attribute, the links start out hidden. Activate the summary again to close the list. Because open is a boolean attribute, even open="false" starts it open. Use nav and ordinary links for site navigation. If the parent item also has a destination, give it a separate link alongside the disclosure control. See WHATWG HTML · details and W3C WAI · Disclosure Navigation.
Try the complete dropdown example
Save the code as dropdown-menu.html and open the file. It has no external dependencies. The three submenu links lead to the HTML, CSS, and JavaScript sections of the same page.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Click-to-open dropdown menu</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
padding: 12px; background: #edf3fa; border: 1px solid #8ca3ba; }
.nav > a, summary { padding: 10px 14px; min-height: 44px; }
.dropdown { position: relative; }
summary { cursor: pointer; }
.panel { position: absolute; top: 100%; left: 0; z-index: 10;
width: min(250px, calc(100vw - 64px)); margin: 0; padding: 8px;
list-style: none; border: 1px solid #8ca3ba; border-radius: 6px;
background: white; box-shadow: 0 6px 18px rgb(0 0 0 / 0.12); }
.panel a { display: block; padding: 10px; color: #154d82; overflow-wrap: anywhere; }
.panel a:hover { background: #edf3fa; }
.nav a:focus-visible, summary:focus-visible { outline: 3px solid #146bcc; outline-offset: 2px; }
.dropdown[open] > summary { background: #d4e5f5; }
section { margin-top: 40px; scroll-margin-top: 20px; }
@media (max-width: 480px) {
.dropdown { flex-basis: 100%; min-width: 0; }
.panel { position: static; width: 100%; }
}
</style>
</head>
<body>
<h1>Course menu</h1>
<nav class="nav" aria-label="Learning navigation">
<a href="#intro">Introduction</a>
<details class="dropdown">
<summary>Courses</summary>
<ul class="panel">
<li><a href="#html">HTML basics</a></li>
<li><a href="#css">CSS basics</a></li>
<li><a href="#javascript">JavaScript basics</a></li>
</ul>
</details>
</nav>
<main>
<section id="intro"><h2>Introduction</h2><p>Open Courses to see the links.</p></section>
<section id="html"><h2>HTML basics</h2><p>Learn how documents are structured.</p></section>
<section id="css"><h2>CSS basics</h2><p>Learn about color and layout.</p></section>
<section id="javascript"><h2>JavaScript basics</h2><p>Learn how to add behavior to a page.</p></section>
</main>
</body>
</html>
Initially you can see the Introduction link and the Courses control. Open Courses and follow a link to its heading. To compare the initial states, add open to the opening details tag and reload the file. Remove it to return to the closed default.
Choose between overlay and in-flow layouts
On wide screens the relatively positioned .dropdown anchors the absolute .panel. The panel starts at top: 100% and overlays the page without pushing it down. At 480px or less, position: static puts the panel back in normal flow, so opening it pushes later content down. Temporarily remove the .panel rule from the media query to compare the two behaviors, then restore it.
If a dropdown at the right edge runs out of room, try left: auto; right: 0 for the wide layout to align the right edges. When an ancestor clips the panel with overflow: hidden, increasing z-index cannot remove the clipping. Check why the ancestor clips its contents. Keeping the panel in flow is an option when clipping must stay. See CSS Positioned Layout · Containing Blocks for rules about positioning and containing blocks.
Keyboard access and closing behavior
Tab to Courses and press Enter or Space to open the list. Tab again to reach its links. While closed, the submenu links are outside the tab sequence. Clicking away, following a link, and pressing Escape do not close this example. For those behaviors, manage the state with JavaScript and return focus to the disclosure control when closing with Escape.




