# Dropdown Menu

> A dropdown that opens on hover and on keyboard focus. No JavaScript.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: dropdown, menu, hover, focus-within, navigation
- Live preview: https://copy-css.com/snippets/dropdown-menu
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```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

```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;
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
