Hamburger Menu in HTML and CSS: 5 Menus to Copy
Updated 2026-10-28. 5 menus.
A hamburger menu is a button with three short lines that opens your site navigation on small screens. Build it as a real button, draw the lines with spans, and style the open state from aria-expanded so the icon and the announced state always match. Each menu here closes on Escape and returns focus.
Start with how many links you have. Four to six pages fit the morphing X or the two-line icon, where the menu simply drops below the header. A longer list with sub-sections reads better in the side drawer, which has room for grouping and a call to action at the bottom.
Then think about the thumb. On phones, a bottom sheet keeps every link within reach of one hand, and the full-width dropdown suits a shop or magazine header that already has a search box and a cart in the bar. The icon animation is a small detail: pick the one that matches the weight of your logo, not the busiest one.
Every version ships as plain HTML and CSS with a few lines of script, and as a React component with the same markup. The script only flips one attribute, so moving between them later means changing the CSS, not the logic.
Compare them
| Variant | Built with | Size (gzipped) | Running cost | Browser support |
|---|---|---|---|---|
| Hamburger Icon That Morphs Into an X | CSS only | 1.5 KB | Three transform transitions and one opacity fade; nothing runs while the menu is idle. | All current browsers |
| Hamburger Icon With Two-Line Asymmetric Morph | CSS only | 1.5 KB | Two bars and four list items transition transform and opacity; idle cost is zero. | All current browsers |
| Hamburger Menu as a Phone Bottom Sheet | CSS only | 2 KB | The sheet slides with translateY and the backdrop fades; both settle in 300ms. | All current browsers |
| Hamburger Menu With Full-Width Dropdown Panel | CSS only | 1.8 KB | A single panel fades and drops 12px with transform; the header never re-lays out. | All current browsers |
| Hamburger Menu With Slide-In Drawer From the Right | CSS only | 2 KB | One translateX on the drawer and one opacity fade on the backdrop per open or close. | All current browsers |
Hamburger Icon That Morphs Into an X
A bakery header with the classic three-line menu icon. Pressing it rotates the top and bottom lines into an X while the middle line shrinks away, and the menu fades down under the header with four large serif links and a short note for each. The notes hide on phones so the links stay big enough to tap. It opens already expanded so you can see both states.
<div class="hmx">
<header class="hmx-bar">
<a href="#" class="hmx-brand">Fenwick Bakehouse</a>
<button type="button" class="hmx-btn" aria-expanded="true" aria-controls="hmx-menu" aria-label="Close menu">
<span class="hmx-icon" aria-hidden="true"><span></span><span></span><span></span></span>
</button>
</header>
<nav id="hmx-menu" class="hmx-menu" aria-label="Main">
<ul>
<li><a href="#"><b>Breads</b><span>Sourdough, rye and the Saturday loaf</span></a></li>
<li><a href="#"><b>Pastries</b><span>Laminated every morning from 4am</span></a></li>
<li><a href="#"><b>Order ahead</b><span>Collect from 7:30 on weekdays</span></a></li>
<li><a href="#"><b>Visit</b><span>14 Quay Street, open six days</span></a></li>
</ul>
</nav>
</div>
<style>
/* Change these: accent, ink, line thickness, transition time. */
.hmx { --hmx-accent: #b45309; --hmx-ink: #1c1917; --hmx-line: 2px; --hmx-speed: .3s; }
.hmx { position: relative; height: 420px; width: calc(100% - 32px); max-width: 48rem; margin: 40px auto; overflow: hidden; border: 1px solid #fde68a; border-radius: 16px; background: #fff; font-family: ui-sans-serif, system-ui, sans-serif; color: var(--hmx-ink); }
.hmx-bar { display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 20px; border-bottom: 1px solid #fef3c7; }
.hmx-brand { font: 600 18px ui-serif, Georgia, serif; color: var(--hmx-ink); text-decoration: none; }
.hmx-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 999px; background: none; color: var(--hmx-ink); cursor: pointer; }
.hmx-btn:hover { background: #fef3c7; }
.hmx-btn:focus-visible, .hmx a:focus-visible { outline: 2px solid var(--hmx-accent); outline-offset: 2px; }
.hmx-icon { position: relative; width: 24px; height: 24px; }
.hmx-icon span { position: absolute; left: 0; width: 24px; height: var(--hmx-line); border-radius: 2px; background: currentColor; transition: transform var(--hmx-speed) ease-out, opacity var(--hmx-speed); }
.hmx-icon span:nth-child(1) { top: 5px; }
.hmx-icon span:nth-child(2) { top: 11px; }
.hmx-icon span:nth-child(3) { top: 17px; }
.hmx-btn[aria-expanded="true"] .hmx-icon span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hmx-btn[aria-expanded="true"] .hmx-icon span:nth-child(2) { transform: scaleX(0); opacity: 0; }
.hmx-btn[aria-expanded="true"] .hmx-icon span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.hmx-menu { position: absolute; inset: 64px 0 auto; padding: 16px 20px 24px; transition: opacity var(--hmx-speed), transform var(--hmx-speed), visibility var(--hmx-speed); }
.hmx-menu[hidden] { display: block; visibility: hidden; opacity: 0; transform: translateY(-8px); }
.hmx-menu ul { margin: 0; padding: 0; list-style: none; }
.hmx-menu li + li { border-top: 1px solid #fef3c7; }
.hmx-menu a { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 16px 8px; border-radius: 8px; color: var(--hmx-ink); text-decoration: none; }
.hmx-menu b { font: 400 24px ui-serif, Georgia, serif; }
.hmx-menu a:hover b { color: var(--hmx-accent); }
.hmx-menu span { font-size: 14px; color: #57534e; }
@media (max-width: 640px) { .hmx-menu span { display: none; } }
@media (prefers-reduced-motion: reduce) { .hmx-icon span, .hmx-menu { transition: none; } }
</style>
<script>
(function () {
document.querySelectorAll(".hmx").forEach(function (root) {
var btn = root.querySelector(".hmx-btn"), menu = root.querySelector(".hmx-menu");
function set(open) {
btn.setAttribute("aria-expanded", open);
btn.setAttribute("aria-label", open ? "Close menu" : "Open menu");
menu.hidden = !open;
}
btn.addEventListener("click", function () { set(btn.getAttribute("aria-expanded") !== "true"); });
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && btn.getAttribute("aria-expanded") === "true") { set(false); btn.focus(); }
});
});
})();
</script>
With reduced motion: The icon and menu switch between states instantly with no transition.
Running cost: Three transform transitions and one opacity fade; nothing runs while the menu is idle.
- Change the line thickness with `h-0.5` on the bars in React or `--hmx-line` in the plain version; if you make them thicker, keep the 6px offsets in step with the gap between lines.
- Recolour the accent through `ring-amber-600` and `hover:text-amber-700`, or `--hmx-accent` in the CSS version.
- Edit the `links` array to change pages and notes; delete the `note` field and its span if you only want labels.
- Slow or speed the morph with `duration-300` or `--hmx-speed`; anything past half a second starts to feel sluggish on a menu.
Full page for Hamburger Icon That Morphs Into an X
Hamburger Icon With Two-Line Asymmetric Morph
A design studio header on near-black with a two-line menu icon: a long line over a short one, aligned right. Hovering stretches the short line to full width, and opening swings both into an X while the page fills with large numbered links that rise in one after another. A contact line sits under the list.
<div class="hm2">
<header class="hm2-head">
<a href="#" class="hm2-brand">okto/studio</a>
<button type="button" class="hm2-btn" aria-expanded="true" aria-controls="hm2-menu" aria-label="Close menu">
<span class="hm2-icon" aria-hidden="true"><span></span><span></span></span>
</button>
</header>
<p class="hm2-line">Identity and web design for small cultural venues.</p>
<nav class="hm2-menu" id="hm2-menu" aria-label="Main">
<ul>
<li><a href="#"><small>01</small>Work</a></li>
<li><a href="#"><small>02</small>Studio</a></li>
<li><a href="#"><small>03</small>Journal</a></li>
<li><a href="#"><small>04</small>Contact</a></li>
</ul>
<p>[email protected] · Rotterdam</p>
</nav>
</div>
<style>
.hm2 { --hm2-accent: #bef264; --hm2-bg: #09090b; --hm2-ease: cubic-bezier(.7,0,.2,1); }
.hm2 { position: relative; height: 460px; width: calc(100% - 32px); max-width: 56rem; margin: 40px auto; overflow: hidden; border-radius: 24px; background: var(--hm2-bg); color: #f4f4f5; font-family: ui-sans-serif, system-ui, sans-serif; }
.hm2 :focus-visible { outline: 2px solid var(--hm2-accent); outline-offset: 3px; }
.hm2-head { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; height: 80px; padding: 0 24px; }
.hm2-brand { font-size: 18px; font-weight: 600; color: inherit; text-decoration: none; }
.hm2-btn { display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 999px; background: none; color: inherit; box-shadow: inset 0 0 0 1px #3f3f46; cursor: pointer; }
.hm2-btn:hover { box-shadow: inset 0 0 0 1px var(--hm2-accent); }
.hm2-icon { position: relative; width: 24px; height: 12px; }
.hm2-icon span { position: absolute; right: 0; height: 2px; width: 24px; border-radius: 2px; background: currentColor; transition: all .5s var(--hm2-ease); }
.hm2-icon span:nth-child(1) { top: 0; }
.hm2-icon span:nth-child(2) { top: 10px; width: 14px; }
.hm2-btn:hover .hm2-icon span:nth-child(2) { width: 24px; }
.hm2-btn[aria-expanded="true"] .hm2-icon span:nth-child(1) { top: 5px; transform: rotate(45deg); }
.hm2-btn[aria-expanded="true"] .hm2-icon span:nth-child(2) { top: 5px; width: 24px; transform: rotate(-45deg); }
.hm2-line { position: absolute; left: 24px; right: 24px; bottom: 40px; margin: 0; max-width: 28rem; font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
.hm2-menu { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 0 24px 40px; background: var(--hm2-bg); transition: opacity .5s, visibility .5s; }
.hm2-menu[hidden] { display: flex; visibility: hidden; opacity: 0; }
.hm2-menu ul { margin: 0; padding: 0; list-style: none; }
.hm2-menu li { transition: transform .5s var(--hm2-ease), opacity .5s; }
.hm2-menu li:nth-child(2) { transition-delay: .06s; }
.hm2-menu li:nth-child(3) { transition-delay: .12s; }
.hm2-menu li:nth-child(4) { transition-delay: .18s; }
.hm2-menu[hidden] li { transform: translateY(16px); opacity: 0; }
.hm2-menu a { display: flex; align-items: baseline; gap: 16px; padding: 4px 0; color: inherit; font-size: 44px; font-weight: 600; letter-spacing: -.02em; text-decoration: none; }
.hm2-menu a:hover { color: var(--hm2-accent); }
.hm2-menu small { width: 24px; font: 12px ui-monospace, Menlo, monospace; color: #a1a1aa; }
.hm2-menu p { margin: 32px 0 0; font-size: 14px; color: #a1a1aa; }
@media (max-width: 640px) { .hm2-menu a { font-size: 36px; } }
@media (prefers-reduced-motion: reduce) { .hm2-icon span, .hm2-menu, .hm2-menu li { transition: none; } }
</style>
<script>
(function () {
document.querySelectorAll(".hm2").forEach(function (root) {
var btn = root.querySelector(".hm2-btn"), menu = root.querySelector(".hm2-menu");
function set(open) {
btn.setAttribute("aria-expanded", open);
btn.setAttribute("aria-label", open ? "Close menu" : "Open menu");
menu.hidden = !open;
}
btn.addEventListener("click", function () { set(menu.hidden); });
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && !menu.hidden) { set(false); btn.focus(); }
});
});
})();
</script>
With reduced motion: The two lines jump straight to the X and the links appear together without rising.
Running cost: Two bars and four list items transition transform and opacity; idle cost is zero.
- The resting short line is `w-3.5` (14px); make it shorter for a bolder offset, or align both lines left by swapping `right-0` for `left-0`.
- The custom curve `cubic-bezier(.7,0,.2,1)` gives the snappy start and soft finish; replace it with `ease-out` for a plainer feel.
- Change the stagger by editing `80 + i * 60` in the inline transition delay, or the `nth-child` delays in the CSS version.
Hamburger Menu as a Phone Bottom Sheet
A climbing gym's mobile site where the menu button raises a sheet from the bottom of the screen instead of dropping a list from the top. Six tiles with line icons sit in a three-column grid within thumb reach, a Done button closes it, and a dark Buy a day pass button anchors the sheet. It is drawn inside a phone frame for the preview.
<div class="hmb-stage">
<div class="hmb">
<header class="hmb-head">
<span class="hmb-brand">Tidewater Climbing</span>
<button type="button" class="hmb-open" aria-expanded="true" aria-controls="hmb-sheet" aria-label="Open menu">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h10"/></svg>
</button>
</header>
<div class="hmb-page">
<div class="hmb-card"><small>Tonight</small><b>Bouldering social, 7pm</b></div>
<div class="hmb-ghost" aria-hidden="true"></div><div class="hmb-ghost" aria-hidden="true"></div>
</div>
<div class="hmb-scrim" aria-hidden="true"></div>
<div class="hmb-sheet" id="hmb-sheet" role="dialog" aria-modal="true" aria-labelledby="hmb-title">
<div class="hmb-grab" aria-hidden="true"></div>
<div class="hmb-top"><h2 id="hmb-title">Menu</h2><button type="button" class="hmb-done">Done</button></div>
<nav aria-label="Main">
<ul class="hmb-grid">
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5h16v15H4zM4 10h16M9 3v4M15 3v4"/></svg>Timetable</a></li>
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>Book a class</a></li>
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 7h18v10H3zM3 11h18"/></svg>Memberships</a></li>
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 12a4 4 0 100-8 4 4 0 000 8zM4 21a8 8 0 0116 0"/></svg>Coaches</a></li>
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 21s7-6.2 7-11.5A7 7 0 005 9.5C5 14.8 12 21 12 21zM12 12a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"/></svg>Find us</a></li>
<li><a href="#"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 21a9 9 0 100-18 9 9 0 000 18zM9.5 9a2.5 2.5 0 114 2c-1 .6-1.5 1.2-1.5 2.5M12 17h.01"/></svg>Help</a></li>
</ul>
</nav>
<a href="#" class="hmb-cta">Buy a day pass</a>
</div>
</div>
</div>
<style>
.hmb-stage { display: flex; justify-content: center; padding: 40px 16px; background: linear-gradient(#e0f2fe, #f0f9ff); font-family: ui-sans-serif, system-ui, sans-serif; }
.hmb { --hmb-accent: #0369a1; position: relative; width: 100%; max-width: 340px; height: 600px; overflow: hidden; box-sizing: border-box; border: 6px solid #0f172a; border-radius: 36px; background: #fff; color: #0f172a; }
.hmb :focus-visible { outline: 2px solid var(--hmb-accent); outline-offset: 2px; }
.hmb-head { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 16px; }
.hmb-brand { font-size: 15px; font-weight: 700; }
.hmb-open { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 999px; background: none; color: inherit; cursor: pointer; }
.hmb-page { padding: 0 16px; }
.hmb-card { display: flex; flex-direction: column; justify-content: space-between; height: 160px; box-sizing: border-box; padding: 16px; border-radius: 16px; background: linear-gradient(135deg, #0ea5e9, #4f46e5); color: #fff; }
.hmb-card small { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #e0f2fe; }
.hmb-card b { font-size: 20px; }
.hmb-ghost { height: 56px; margin-top: 12px; border-radius: 12px; background: #f1f5f9; }
.hmb-scrim { position: absolute; inset: 0; background: rgba(15,23,42,.4); transition: opacity .3s; }
.hmb-sheet { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px 24px; border-radius: 24px 24px 0 0; background: #fff; box-shadow: 0 -12px 40px rgba(15,23,42,.18); transition: transform .3s ease-out, visibility .3s; }
.hmb:not([data-open]) .hmb-scrim { opacity: 0; pointer-events: none; }
.hmb:not([data-open]) .hmb-sheet { transform: translateY(100%); visibility: hidden; }
.hmb-grab { width: 40px; height: 6px; margin: 0 auto; border-radius: 3px; background: #cbd5e1; }
.hmb-top { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.hmb-top h2 { margin: 0; font-size: 16px; }
.hmb-done { height: 40px; padding: 0 12px; border: 0; border-radius: 999px; background: none; color: var(--hmb-accent); font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.hmb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.hmb-grid a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 80px; border-radius: 16px; background: #f8fafc; color: #1e293b; font-size: 12px; font-weight: 500; text-decoration: none; }
.hmb-grid a:hover { background: #f0f9ff; }
.hmb-grid svg { width: 22px; height: 22px; fill: none; stroke: var(--hmb-accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hmb-cta { display: flex; align-items: center; justify-content: center; height: 48px; margin-top: 12px; border-radius: 16px; background: #0f172a; color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
@media (prefers-reduced-motion: reduce) { .hmb-scrim, .hmb-sheet { transition: none; } }
</style>
<script>
(function () {
document.querySelectorAll(".hmb").forEach(function (root) {
var opener = root.querySelector(".hmb-open");
function set(open) {
root.toggleAttribute("data-open", open);
opener.setAttribute("aria-expanded", open);
if (!open) opener.focus();
}
set(true);
opener.addEventListener("click", function () { set(true); root.querySelector(".hmb-done").focus(); });
root.querySelector(".hmb-done").addEventListener("click", function () { set(false); });
root.querySelector(".hmb-scrim").addEventListener("click", function () { set(false); });
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && root.hasAttribute("data-open")) set(false);
});
});
})();
</script>
With reduced motion: The sheet appears at the bottom of the screen without sliding up.
Running cost: The sheet slides with translateY and the backdrop fades; both settle in 300ms.
- Edit `items` to change tiles; each `path` is a 24 by 24 icon drawn with a single stroke.
- Switch the grid from `grid-cols-3` to `grid-cols-2` for longer labels, and raise the tile height from `h-20` if they wrap.
- Drop the phone frame by removing the `border-[6px]` and `rounded-[2.25rem]` classes when you place it in a real page.
Hamburger Menu With Full-Width Dropdown Panel
A ceramics shop header with the menu button on the left, a centred wordmark and the bag on the right. The button opens a white panel across the full width under the bar, with three columns of links and a featured collection card. On phones the columns stack and the card is dropped so the links come first.
<div class="hmf">
<header class="hmf-head">
<button type="button" class="hmf-btn" aria-expanded="true" aria-controls="hmf-panel">
<span class="hmf-icon" aria-hidden="true"><span></span><span></span><span></span></span>
<span class="hmf-word">Close</span>
</button>
<a href="#" class="hmf-brand">Copper & Clay</a>
<a href="#" class="hmf-bag">Bag (2)</a>
</header>
<div class="hmf-hero"><h2>Autumn glazes are in</h2><p>Thrown by hand in a small studio by the river.</p></div>
<div class="hmf-panel" id="hmf-panel">
<nav aria-label="Main" class="hmf-grid">
<div><p>Shop</p><ul><li><a href="#">Mugs and cups</a></li><li><a href="#">Plates and bowls</a></li><li><a href="#">Vases</a></li><li><a href="#">Seconds sale</a></li></ul></div>
<div><p>Studio</p><ul><li><a href="#">Book a wheel class</a></li><li><a href="#">Commissions</a></li><li><a href="#">Our glazes</a></li></ul></div>
<div><p>Help</p><ul><li><a href="#">Delivery</a></li><li><a href="#">Returns</a></li><li><a href="#">Care guide</a></li></ul></div>
<a href="#" class="hmf-card"><small>New</small><b>Ember speckle collection</b><span>Shop the range</span></a>
</nav>
</div>
</div>
<style>
.hmf { --hmf-accent: #9f1239; --hmf-paper: #faf7f2; --hmf-ink: #1c1917; }
.hmf { position: relative; height: 500px; width: calc(100% - 32px); max-width: 64rem; margin: 40px auto; overflow: hidden; border-radius: 12px; background: var(--hmf-paper); box-shadow: 0 0 0 1px #d6d3d1; font-family: ui-sans-serif, system-ui, sans-serif; color: var(--hmf-ink); }
.hmf :focus-visible { outline: 2px solid var(--hmf-accent); outline-offset: 2px; }
.hmf-head { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 16px; border-bottom: 1px solid #e7e5e4; background: var(--hmf-paper); }
.hmf-btn, .hmf-bag { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--hmf-ink); font: 500 14px ui-sans-serif, system-ui, sans-serif; text-decoration: none; cursor: pointer; }
.hmf-btn:hover, .hmf-bag:hover { background: #e7e5e4; }
.hmf-brand { margin: 0 auto; font: 20px ui-serif, Georgia, serif; color: var(--hmf-ink); text-decoration: none; }
.hmf-icon { position: relative; width: 20px; height: 16px; }
.hmf-icon span { position: absolute; left: 0; height: 2px; width: 20px; border-radius: 2px; background: currentColor; transition: all .3s; }
.hmf-icon span:nth-child(1) { top: 0; }
.hmf-icon span:nth-child(2) { top: 7px; width: 14px; }
.hmf-icon span:nth-child(3) { top: 14px; }
.hmf-btn[aria-expanded="true"] .hmf-icon span:nth-child(1) { top: 7px; transform: rotate(45deg); }
.hmf-btn[aria-expanded="true"] .hmf-icon span:nth-child(2) { width: 0; opacity: 0; }
.hmf-btn[aria-expanded="true"] .hmf-icon span:nth-child(3) { top: 7px; transform: rotate(-45deg); }
.hmf-hero { padding: 64px 24px 0; text-align: center; }
.hmf-hero h2 { margin: 0; font: 36px ui-serif, Georgia, serif; }
.hmf-hero p { color: #57534e; }
.hmf-panel { position: absolute; left: 0; right: 0; top: 64px; max-height: calc(100% - 64px); overflow-y: auto; background: #fff; border-bottom: 1px solid #e7e5e4; box-shadow: 0 12px 30px rgba(0,0,0,.08); transition: opacity .3s, transform .3s ease-out, visibility .3s; }
.hmf-panel[hidden] { display: block; visibility: hidden; opacity: 0; transform: translateY(-12px); }
.hmf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px 24px; padding: 32px 24px; }
@media (min-width: 640px) { .hmf-grid { grid-template-columns: 1fr 1fr 1fr 1.2fr; } }
.hmf-grid p { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .15em; text-transform: uppercase; color: var(--hmf-accent); }
.hmf-grid ul { margin: 12px 0 0; padding: 0; list-style: none; }
.hmf-grid li a { display: block; padding: 6px 0; color: #292524; font-size: 15px; text-decoration: none; }
.hmf-grid li a:hover { color: var(--hmf-accent); }
.hmf-card { display: none; flex-direction: column; justify-content: flex-end; padding: 20px; border-radius: 8px; background: linear-gradient(135deg, #fecdd3, #ffedd5, #fef3c7); color: var(--hmf-ink); text-decoration: none; }
@media (min-width: 640px) { .hmf-card { display: flex; } }
.hmf-card small { font-size: 12px; font-weight: 600; letter-spacing: .15em; text-transform: uppercase; color: #881337; }
.hmf-card b { margin-top: 4px; font: 400 20px ui-serif, Georgia, serif; }
.hmf-card span { margin-top: 4px; font-size: 14px; color: #44403c; }
@media (prefers-reduced-motion: reduce) { .hmf-icon span, .hmf-panel { transition: none; } }
</style>
<script>
(function () {
document.querySelectorAll(".hmf").forEach(function (root) {
var btn = root.querySelector(".hmf-btn"), panel = root.querySelector(".hmf-panel"), word = root.querySelector(".hmf-word");
function set(open) {
btn.setAttribute("aria-expanded", open);
word.textContent = open ? "Close" : "Menu";
panel.hidden = !open;
}
btn.addEventListener("click", function () { set(btn.getAttribute("aria-expanded") !== "true"); });
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && !panel.hidden) { set(false); btn.focus(); }
});
});
})();
</script>
With reduced motion: The panel shows and hides at once and the icon swaps to an X without rotating.
Running cost: A single panel fades and drops 12px with transform; the header never re-lays out.
- Add or rename columns in `columns`; the grid template `sm:grid-cols-[1fr_1fr_1fr_1.2fr]` gives the featured card a little extra width.
- Change the label colour from `text-rose-800` or the `--hmf-accent` variable to match your brand.
- Remove the gradient card if you have no campaign to feature; the three columns fill the row on their own.
Hamburger Menu With Slide-In Drawer From the Right
A physiotherapy clinic header whose Menu button slides a white drawer in from the right over a dimmed page. Links sit in two labelled groups, and a full-width Book a session button waits at the bottom of the drawer. It works as a dialog: Tab stays inside, Escape or a backdrop click closes it and focus returns to the button.
<div class="hmd">
<header class="hmd-head">
<a href="#" class="hmd-brand">Northpoint Physio</a>
<button type="button" class="hmd-open" aria-expanded="true" aria-controls="hmd-drawer">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
Menu
</button>
</header>
<div class="hmd-hero">
<p class="hmd-kicker">Same-week appointments</p>
<h2>Get moving again without the waiting list</h2>
<p>Assessment and a treatment plan in your first 45-minute session.</p>
</div>
<div class="hmd-scrim" aria-hidden="true"></div>
<div class="hmd-drawer" id="hmd-drawer" role="dialog" aria-modal="true" aria-labelledby="hmd-title">
<div class="hmd-top">
<h2 id="hmd-title">Menu</h2>
<button type="button" class="hmd-close" aria-label="Close menu">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>
</button>
</div>
<nav aria-label="Main" class="hmd-nav">
<p>Treatments</p>
<ul><li><a href="#">Sports injuries</a></li><li><a href="#">Back and neck pain</a></li><li><a href="#">Pre and post surgery</a></li><li><a href="#">Pilates classes</a></li></ul>
<p>Clinic</p>
<ul><li><a href="#">Our physios</a></li><li><a href="#">Prices</a></li><li><a href="#">Contact</a></li></ul>
</nav>
<div class="hmd-foot"><a href="#" class="hmd-cta">Book a session</a></div>
</div>
</div>
<style>
.hmd { --hmd-accent: #0f766e; --hmd-ink: #042f2e; --hmd-width: 300px; }
.hmd { position: relative; height: 480px; width: calc(100% - 32px); max-width: 56rem; margin: 40px auto; overflow: hidden; border-radius: 16px; background: #fff; box-shadow: 0 0 0 1px rgba(4,47,46,.1); font-family: ui-sans-serif, system-ui, sans-serif; color: var(--hmd-ink); }
.hmd a, .hmd button { font: inherit; }
.hmd :focus-visible { outline: 2px solid var(--hmd-accent); outline-offset: 2px; }
.hmd-head { display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 20px; }
.hmd-brand { font-weight: 700; color: var(--hmd-ink); text-decoration: none; }
.hmd-open { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; border: 1px solid #99f6e4; border-radius: 999px; background: #fff; color: var(--hmd-ink); font-size: 14px; font-weight: 500; cursor: pointer; }
.hmd-hero { padding: 40px 20px 0; }
.hmd-kicker { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--hmd-accent); }
.hmd-hero h2 { margin: 12px 0 0; max-width: 28rem; font-size: 32px; line-height: 1.15; letter-spacing: -.02em; }
.hmd-hero p:last-child { max-width: 24rem; color: #475569; }
.hmd-scrim { position: absolute; inset: 0; background: rgba(4,47,46,.4); transition: opacity .3s; }
.hmd-drawer { position: absolute; top: 0; right: 0; bottom: 0; display: flex; flex-direction: column; width: var(--hmd-width); max-width: 86%; background: #fff; box-shadow: -20px 0 50px rgba(0,0,0,.2); transition: transform .3s ease-out, visibility .3s; }
.hmd:not([data-open]) .hmd-scrim { opacity: 0; pointer-events: none; }
.hmd:not([data-open]) .hmd-drawer { transform: translateX(100%); visibility: hidden; }
.hmd-top { display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 20px; border-bottom: 1px solid #f1f5f9; }
.hmd-top h2 { margin: 0; font-size: 14px; }
.hmd-close { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 999px; background: none; color: #475569; cursor: pointer; }
.hmd-close:hover { background: #f1f5f9; }
.hmd-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.hmd-nav p { margin: 0; padding: 0 12px 4px; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #475569; }
.hmd-nav ul { margin: 0 0 16px; padding: 0; list-style: none; }
.hmd-nav a { display: flex; align-items: center; height: 40px; padding: 0 12px; border-radius: 8px; color: #1e293b; font-size: 15px; text-decoration: none; }
.hmd-nav a:hover { background: #f0fdfa; }
.hmd-foot { padding: 16px; border-top: 1px solid #f1f5f9; }
.hmd-cta { display: flex; align-items: center; justify-content: center; height: 44px; border-radius: 999px; background: var(--hmd-accent); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
@media (prefers-reduced-motion: reduce) { .hmd-scrim, .hmd-drawer { transition: none; } }
</style>
<script>
(function () {
document.querySelectorAll(".hmd").forEach(function (root) {
var opener = root.querySelector(".hmd-open"), drawer = root.querySelector(".hmd-drawer");
function set(open) {
root.toggleAttribute("data-open", open);
opener.setAttribute("aria-expanded", open);
if (!open) opener.focus();
}
set(true);
opener.addEventListener("click", function () { set(true); root.querySelector(".hmd-close").focus(); });
root.querySelector(".hmd-close").addEventListener("click", function () { set(false); });
root.querySelector(".hmd-scrim").addEventListener("click", function () { set(false); });
document.addEventListener("keydown", function (e) {
if (!root.hasAttribute("data-open")) return;
if (e.key === "Escape") return set(false);
if (e.key !== "Tab" || !drawer.contains(document.activeElement)) return;
var items = drawer.querySelectorAll("a, button"), first = items[0], last = items[items.length - 1];
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
});
});
})();
</script>
With reduced motion: The drawer and the dimmed backdrop appear and disappear without sliding.
Running cost: One translateX on the drawer and one opacity fade on the backdrop per open or close.
- Set the drawer width with `w-[300px]` in React or `--hmd-width` in the plain version; the `max-w-[86%]` cap keeps a strip of page visible on small phones.
- Edit `groups` to add sections; each title becomes a small uppercase label above its links.
- Swap `translate-x-full` for `-translate-x-full` and `right-0` for `left-0` to slide the drawer from the left instead.
Performance notes
The icon morphs move three or two thin bars with transform and fade them with opacity, which the browser handles without recalculating layout. The open menus slide with translate and fade in, so even the full-height drawer costs one composited layer while it moves and nothing once it settles.
There is no animation library and no resize listener. Each menu adds one keydown listener while it is open and removes it on close in the React version, and the plain version keeps a single listener per menu. A closed menu uses visibility hidden, so its links stay out of the tab order without being removed from the page.
Questions
Can I make a hamburger menu with only HTML and CSS?
You can, using a hidden checkbox and the :checked selector, but the control is then announced as a checkbox and cannot expose aria-expanded or close on Escape. A button and roughly ten lines of JavaScript give a menu that behaves properly for keyboard and screen reader users.
What attributes does an accessible menu button need?
A visible or aria-label name such as Open menu, aria-expanded set to true or false, and aria-controls naming the id of the panel it opens. Do not add role menu to an ordinary list of site links; that role is for application menus with arrow-key behaviour.
At what screen width should the hamburger appear?
Show it when your links no longer fit on one line at a comfortable size, which for five or six short links is usually somewhere below 768 pixels. Pick the breakpoint from your real link labels, not from a framework default.
How do I stop the page scrolling behind an open drawer?
Set overflow hidden on the body while the drawer is open and restore it on close. The demos here sit inside a fixed-height frame instead, so they leave the page scroll alone; add the body lock when you move one into a real layout.
Should the menu trap focus while it is open?
A drawer or bottom sheet that covers the page and dims it behaves like a dialog, so keep Tab inside it until it closes. A dropdown that sits under the header without covering content does not need a trap; Escape and a working close button are enough.
Also in the gallery: CSS Hamburger Menu Collection with 12 Animated Icons and an Accessible Mobile Nav, Navbar with Centered Links, CTA Button and Mobile Menu, Navy Circle That Grows From the Menu Button.
More collections: React Sidebar Components With Tailwind, Full-Screen Menus and Menu Reveals, React Tab Components: 5 Accessible Tab Styles. All navbars. Build your site free to have a full site built around them.
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App