<button class="ham">
    <!-- X and menu icon SVGs from material icons https://material.io/resources/icons/ -->
    <span class="menuIcon material-icons">
      menu
    </span>
    <span class="xIcon material-icons">
      close
    </span>
  </button>
  <ul class="menu">
    <li><a class="menuLink" href="#">Home</a></li>
    <li><a class="menuLink" href="#">Profile</a></li>
    <li><a class="menuLink" href="#">About</a></li>
    <li><a class="menuLink" href="#">Contacts</a></li>
  </ul>
* {
  margin: 0;
  box-sizing: border-box;
}

.ham {
  position: fixed;
  /* keep the hamburger button above everything */
  z-index: 100;
  top: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border: black solid 1px;
  background: white;
  cursor: pointer;
}

.xIcon {
  display: none;
}

.menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  background: black;
  color: white;
  transform: translateY(-100%);
  transition: transform 0.2s;
  list-style: none;
  padding-top: 4rem;
}

.showMenu {
  transform: translateY(0);
}

li {
  padding: 1rem 0;
}

.menuLink {
  display: inline;
  font-size: 2rem;
  color: white;
  text-decoration: none;
}

.menuLink:hover {
  text-decoration: underline;
}
var menu = document.querySelector(".menu")
var ham = document.querySelector(".ham")
var xIcon = document.querySelector(".xIcon")
var menuIcon = document.querySelector(".menuIcon")

ham.addEventListener("click", toggleMenu)

function toggleMenu() {
  if (menu.classList.contains("showMenu")) {
    menu.classList.remove("showMenu");
    xIcon.style.display = "none";
    menuIcon.style.display = "block";
  } else {
    menu.classList.add("showMenu");
    xIcon.style.display = "block";
    menuIcon.style.display = "none";
  }
}

var menuLinks = document.querySelectorAll(".menuLink")

menuLinks.forEach(
  function (menuLink) {
    menuLink.addEventListener("click", toggleMenu)
  }
)

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.