Sample Humberger Menu With Open Close Icons

Here's a simple example of how to create a hambergur menu with different open and close icons using HTML and CSS only (no JavaScript needed).

This approach uses a hidden checkbox to toggle the menu and change the icons.

HTML Sample Code


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hamburger Menu Example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<nav class="navbar">
<input type="checkbox" id="menu-toggle">
<label for="menu-toggle" class="menu-icon">
<span class="open-icon">&#9776;</span>    <!-- ? Hamburger icon -->
<span class="close-icon">&times;</span>   <!--  X Close icon -->
</label>

<ul class="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>

</body>
</html>

CSS (Styles.css



/* --- Reset and base styles --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Poppins", sans-serif;
  background: #f4f4f4;
}

/* --- Navbar Container --- */
.navbar {
  background-color: blue;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  position: relative;
}

/* --- Hide the checkbox --- */
#menu-toggle {
  display: none;
}

/* --- Menu Icon --- */
.menu-icon {
  cursor: pointer;
  font-size: 28px;
  color: white;
  display: inline-block;
}

.menu-icon .close-icon {
  display: none;
}

/* --- Navigation Menu --- */
.menu {
  list-style: none;
  display: none;
  flex-direction: column;
  width: 100%;
  background-color: blue;
  position: absolute;
  top: 60px;
  left: 0;
}
.menu li a {
  color: white;
  text-decoration: none;
  padding: 12px 20px;
  display: block;
  transition: background 0.3s;
}

.menu li a:hover {
  background: red; 
}

/* --- Toggle Icons and Menu --- */
#menu-toggle:checked + .menu-icon .open-icon {
  display: none;
}

#menu-toggle:checked + .menu-icon .close-icon {
  display: inline;
}

#menu-toggle:checked ~ .menu {
  display: flex;
}

/* --- Responsive for Larger Screens --- */
@media (min-width: 768px) {
  .menu {
    display: flex !important;
    flex-direction: row;
    align-items: left;
    justify-content: flex-end;
    background: none;
    position: static;
    width: auto;
  }
 .menu-icon {
    display: none;
  }
}

RESULT HUMBERGER MENU with different open and close icons

All Rights Reserved, Copyright © PT. InetUtama Systemindo 2025