HTML to Webflow examples
Navbar: mobile menu with JavaScript
A hamburger button opens the menu on mobile. The lines change to an X.
- JavaScript
- Responsive
- Hover states
What you receive in Webflow
- 17 native elements and 9 classes.
- Breakpoints: mobile landscape (767px).
- States: hover.
- 2 Embed elements keep the CSS or script that Webflow cannot express. To edit an Embed, you must have a paid Webflow site plan.
How to paste it
- Click Copy for Webflow.
- Open your page in the Webflow Designer.
- Press ⌘V or Ctrl+V.
HTML
<nav class="nb2">
<div class="nb2-bar">
<a href="#" class="nb2-logo"><span class="nb2-mark"></span>Northwind</a>
<div class="nb2-menu">
<a href="#" class="nb2-link">Product</a>
<a href="#" class="nb2-link">Solutions</a>
<a href="#" class="nb2-link">Pricing</a>
<a href="#" class="nb2-link">Docs</a>
<a href="#" class="nb2-cta">Start free trial</a>
</div>
<button class="nb2-burger" aria-label="Open menu" aria-expanded="false">
<span class="nb2-line"></span><span class="nb2-line"></span><span class="nb2-line"></span>
</button>
</div>
</nav>
<style>
.nb2 { font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background: #ffffff; border-bottom: 1px solid #e7e5e4; position: relative; z-index: 20; }
.nb2-bar { max-width: 1160px; margin: 0 auto; padding: 0 24px; height: 68px; display: flex; align-items: center; justify-content: space-between; }
.nb2-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; color: #1c1917; text-decoration: none; letter-spacing: -0.01em; }
.nb2-mark { width: 26px; height: 26px; border-radius: 8px; background: #ea580c; box-shadow: inset -8px -8px 0 #9a3412; }
.nb2-menu { display: flex; align-items: center; gap: 28px; }
.nb2-link { color: #44403c; text-decoration: none; font-size: 15px; transition: color 0.2s ease; }
.nb2-link:hover { color: #ea580c; }
.nb2-cta { background: #1c1917; color: #ffffff; text-decoration: none; font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: 8px; transition: background-color 0.2s ease; }
.nb2-cta:hover { background: #ea580c; }
.nb2-burger { display: none; width: 40px; height: 40px; padding: 0; border: 0; background: transparent; cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 5px; }
.nb2-line { display: block; width: 22px; height: 2px; background: #1c1917; border-radius: 2px; transition: transform 0.3s ease, opacity 0.2s ease; }
.nb2.is-open .nb2-line:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nb2.is-open .nb2-line:nth-child(2) { opacity: 0; }
.nb2.is-open .nb2-line:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
@media (max-width: 767px) {
.nb2-burger { display: flex; }
.nb2-menu { display: none; position: absolute; top: 68px; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 0; padding: 8px 24px 24px; background: #ffffff; border-bottom: 1px solid #e7e5e4; }
.nb2.is-open .nb2-menu { display: flex; }
.nb2-link { padding: 14px 0; border-bottom: 1px solid #f5f5f4; font-size: 17px; }
.nb2-cta { margin-top: 16px; text-align: center; padding: 14px 16px; font-size: 16px; }
}
</style>
<script>
document.querySelectorAll(".nb2").forEach(function (nav) {
var burger = nav.querySelector(".nb2-burger");
burger.addEventListener("click", function () {
var open = nav.classList.toggle("is-open");
burger.setAttribute("aria-expanded", open ? "true" : "false");
});
});
</script>