Changing Hamburger Menu Bar into Close Button



very simple code to change your hamburger menu bar into close button




 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.icon').click(function(){
                $('.icon').toggleClass('active');
            })
        })
    </script>
    
    <title>Hamburger</title>
</head>
<body>
  <h1 style="font-family: sans-serif; text-align:center;"> click me :)</h1>
    <div class="icon">
        <div class="hamburger"></div>
    </div>
</body>
</html>                    
                  
                



 body {
    margin: 0;
    padding: 0;
    background: #ff5c40;
}

.icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 80px;
    height: 80px;
    cursor: pointer;
}

.hamburger {
    width: 50px;
    height: 6px;
    background: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: 0.6s;
}

.hamburger::before,
.hamburger::after { 
    content: '';
    position: absolute;
    width: 50px;
    height: 6px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: 0.6s;
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: 50px;
    height: 6px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: 0.6s;
}

.hamburger::before {
    top: -16px;
}

.hamburger::after {
    top: 16px;
}

.icon.active .hamburger {
    background: rgba(0,0,0,0);
    box-shadow: 0 2px 5px rgba(0,0,0,0);
}

.icon.active .hamburger::before {
    top: 0;
    transform: rotate(45deg);
}

.icon.active .hamburger::after {
    top: 0;
    transform: rotate(135deg);
}