About this snippet

Create an immersive navigation experience with this fullscreen overlay. When the menu button is clicked, the navigation expands to cover the entire screen, giving you plenty of space for large, readable links.

Size
1.7 KB
Uses
HTML, CSS, JavaScript
Loads
Nothing external
Views
446
<button id="menuBtn" class="menu-trigger">Menu</button>
<div id="fullNav" class="full-overlay">
  <button id="closeBtn" class="close-trigger">&times;</button>
  <nav class="overlay-content">
    <a href="#">Home</a>
    <a href="#">Work</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
  </nav>
</div>
.menu-trigger {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  padding: 10px 20px;
  background: #111827;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}
.full-overlay {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  background-color: #111827;
  overflow-x: hidden;
  transition: width 0.4s cubic-bezier(0.77, 0, 0.175, 1);
}
.full-overlay.open {
  width: 100%;
}
.overlay-content {
  position: relative;
  top: 25%;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.overlay-content a {
  text-decoration: none;
  font-size: 2.5rem;
  color: #9ca3af;
  transition: color 0.3s;
  font-weight: 700;
}
.overlay-content a:hover {
  color: #fff;
}
.close-trigger {
  position: absolute;
  top: 20px;
  right: 45px;
  font-size: 3rem;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
}
const menuBtn = document.getElementById("menuBtn");
const closeBtn = document.getElementById("closeBtn");
const nav = document.getElementById("fullNav");

menuBtn.addEventListener("click", () => {
  nav.classList.add("open");
});

closeBtn.addEventListener("click", () => {
  nav.classList.remove("open");
});
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save