CSS Dropdown Menu
A dropdown that opens on hover and on keyboard focus. No JavaScript.
HTML
<div class="dropdown">
<button class="dropdown-toggle">Account ▾</button>
<ul class="dropdown-menu">
<li><a href="#">Profile</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Sign out</a></li>
</ul>
</div>
CSS
.dropdown {
position: relative;
display: inline-block;
font: 500 15px system-ui, sans-serif;
}
.dropdown-toggle {
padding: 10px 16px;
border: 1px solid #e5e7eb;
border-radius: 10px;
background: #fff;
color: #111;
font: inherit;
cursor: pointer;
}
.dropdown-menu {
position: absolute;
top: calc(100% + 8px);
left: 0;
min-width: 170px;
margin: 0;
padding: 6px;
list-style: none;
border: 1px solid #e5e7eb;
border-radius: 12px;
background: #fff;
box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.18);
opacity: 0;
visibility: hidden;
transform: translateY(-6px);
transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}
/* Invisible bridge so the menu stays open while the pointer crosses the gap */
.dropdown-menu::before {
content: "";
position: absolute;
top: -10px;
right: 0;
left: 0;
height: 10px;
}
.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu {
opacity: 1;
visibility: visible;
transform: none;
}
.dropdown-menu a {
display: block;
padding: 8px 12px;
border-radius: 8px;
color: #111;
text-decoration: none;
}
.dropdown-menu a:hover {
background: #f3f4f6;
}
About this CSS Dropdown Menu
This CSS Dropdown Menu is 62 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses transitions, transforms and box shadows. 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:
#e5e7eb#fff#111#f3f4f6
How to use this dropdown menu
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.dropdownclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein 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.