JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
CSS
.container {
display: inline-block;
cursor: pointer;
height: 50px;
width: 50px;
}
.bar1, .bar2, .bar3 {
width: 100%;
height: 5px;
background-color: #454545;
border-radius: 5px;
transform-origin: right;
transition: 0.4s;
}
.bar2 {
margin: 18px 0;
}
.change .bar1,
.change .bar3 {
width: 73.5px;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-12px, -18px);
transform: rotate(-45deg) translate(-12px, -18px);
}
.change .bar3 {
width: 73.5px;
-webkit-transform: rotate(45deg) translate(-14px, 18px);
transform: rotate(45deg) translate(-14px, 18px);
}
.change .bar2 {
opacity: 0;
}
JavaScript
function myFunction(x) {
x.classList.toggle("change");
}