Toggle Menu Icon Using JavaScript | Menu Toggle Icon

Hello everyone, you can learn how to create a Toggle Menu Icon Using JavaScript in this blog. So if you want to learn then follow all the steps carefully.  

Source Code Of Toggle Menu Icon

Step 1: Create Index.html File

Create one file with the name index.html and paste the below code in this file. 
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="">
    <title>Menu Toggle Icon</title>

    <div class="toggle"><i class="fa fa-bars"></i></div>


        let btn = document.querySelector(".toggle");
        let icon = btn.querySelector(".fa-bars");

        btn.onclick = function (){
                icon.classList.replace("fa-bars", "fa-times");
                icon.classList.replace("fa-times", "fa-bars");


Step 2: Create style.css File

Create one file with the name style.css and paste the below code in this file.

    margin: 0;
    padding: 0;
    box-sizing: border-box;

    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e6091;

    background: #ffd60a;
    padding: 10px 15px;
    cursor: pointer;

.toggle i{
    font-size: 40px;
    transition: 0.2s;

That’s It. if you face any error/problem then comment below or Download this code file and then try again. This file is a Zip file so after download you have to extract it.

For Download Code You have to wait 30 seconds.

Leave a Comment