Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript
Next article icon

Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript

Last Updated : 30 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To create a Mobile Toggle Navigation Menu you need HTML, CSS, and JavaScript. If you want to attach the icons with the menu then you need a font-awesome CDN link. This article is divided into two sections: Creating Structure and Designing Structure.

A glimpse of complete Navigation: 


Creating Structure: In this section, we will create a basic site structure and also attach the CDN link of the Font-Awesome for the icons which will be used as a menu icon. 
 

CDN links for the Icons from the Font Awesome: 

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

HTML code to make the structure: 

HTML
<!DOCTYPE html> <html>  <head>     <title>Mobile Navigation Bar</title>     <meta name="viewport"            content="width=device-width, initial-scale=1"> </head>  <body>     <div class="menu-list">          <!-- Logo and navigation menu -->         <div class="geeks">             <a href="#" class="">GeeksforGeeks</a>             <div id="menus">                 <a href="#">Language</a>                 <a href="#">Practice</a>                 <a href="#">Interview</a>                 <a href="#">Puzzle</a>              </div>                          <!-- Bar icon for navigation -->             <a href="javascript:void(0);" class="icon"                onclick="geeksforgeeks()">                <i onclick="myFunction(this)"                          class="fa fa-plus-circle">                </i>             </a>         </div>     </div> </body>  </html> 


Designing Structure: In the previous section, we created the structure of the basic website where we are going to use the menu icon. In this section, we will design the structure for the navigation bar. 

CSS code of structure: 

HTML
/* Navigation bar styling */ .menu-list {     max-width: 300px;     margin: auto;     height: 500px;     color: white;     background-color: green;     border-radius: 10px; }  /* Logo, navigation menu styling */ .geeks {     overflow: hidden;     background-color: #111;     position: relative; }  /* Styling navigation menu */ .geeks #menus {     display: none; }  /* Link specific styling */ .geeks a {     text-decoration: none;     color: white;     padding: 14px 16px;     font-size: 16px;     display: block; }  /* Navigation toggle menu styling */ .geeks a.icon {     display: block;     position: absolute;     right: 0;     top: 0; }  /* Hover effect on navigation logo and menu */ .geeks a:hover {     background-color: #ddd;     color: black; } 

JavaScript code for the animation menu: 

JavaScript
// Function to toggle the bar function geeksforgeeks() {     let x = document.getElementById("menus");          if (x.style.display === "block") {         x.style.display = "none";     } else {         x.style.display = "block";     } }  // Function to toggle the plus menu into minus function myFunction(x) {     x.classList.toggle("fa-minus-circle"); } 


Combine the HTML, CSS, and JavaScript code: This is the final code after combining the above sections. It will be the mobile navigation animated menu. 

Example: 

HTML
<!DOCTYPE html> <html>  <head>     <title>Mobile Navigation Bar</title>     <meta name="viewport" content=         "width=device-width, initial-scale=1">     <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">      <style>         /* Navigation bar styling */         .menu-list {             max-width: 300px;             margin: auto;             height: 500px;             color: white;             background-color: green;             border-radius: 10px;         }          /* Logo, navigation menu styling */         .geeks {             overflow: hidden;             background-color: #111;             position: relative;         }          /* Styling navigation menu */         .geeks #menus {             display: none;         }          /* Link specific styling */         .geeks a {             text-decoration: none;             color: white;             padding: 14px 16px;             font-size: 16px;             display: block;         }          /* Navigation toggle menu styling */         .geeks a.icon {             display: block;             position: absolute;             right: 0;             top: 0;         }          /* Hover effect on navigation logo and menu */         .geeks a:hover {             background-color: #ddd;             color: black;         }     </style> </head>  <body>     <div class="menu-list">          <!-- Logo and navigation menu -->         <div class="geeks">             <a href="#" class="">                 GeeksforGeeks             </a>                          <div id="menus">                 <a href="#">Language</a>                 <a href="#">Practice</a>                 <a href="#">Interview</a>                 <a href="#">Puzzle</a>             </div>              <!-- Bar icon for navigation -->             <a href="javascript:void(0);"                  class="icon" onclick="geeksforgeeks()">                 <i onclick="myFunction(this)"                      class="fa fa-plus-circle">                 </i>             </a>         </div>     </div>      <script>          // Function to toggle the bar         function geeksforgeeks() {             let x = document.getElementById("menus");             if (x.style.display === "block") {                 x.style.display = "none";             } else {                 x.style.display = "block";             }         }          // Function to toggle the plus menu into minus         function myFunction(x) {             x.classList.toggle("fa-minus-circle");         }     </script> </body>  </html> 

Output: 



Next Article
Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript

S

Sabya_Samadder
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-functions
  • JavaScript-Projects

Similar Reads

    How to create a revealing sidebar using HTML CSS and JavaScript?
    A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked. ApproachCreate an HTML file with headings and
    3 min read
    Create A Bottom Navigation Menu using HTML and CSS
    This article will show you how to create a bottom navigation menu using HTML and CSS. The navigation menu is an essential component in modern web design. It allows users to navigate through a website easily. Here, we use HTML to create the structure of the Bottom Navigation menu, and CSS add styles
    2 min read
    How to create a Responsive Bottom Navigation Menu with CSS and JavaScript.
    A responsive bottom navigation menu provides mobile-friendly access to important links. We will see how to create a responsive bottom navigation menu that adjusts to different screen widths. The menu will include elements like Home, Contact, and About. When viewed on a smaller screen, a hamburger me
    2 min read
    Design a Navigation Bar with Toggle Dark Mode in HTML CSS & JavaScript
    One can create a navigation bar with a toggle switch for dark mode using HTML, CSS, and JavaScript. If we use the dark mode effect in our website then it can attract user attention and users can use our website in any situation. With the help of JavaScript, we'll implement the functionality to toggl
    6 min read
    How to Create a Portfolio Website using HTML CSS and JavaScript ?
    A portfolio website is a website that represents you online on the web pages. It contains different sections like Introduction to Yourself, About You, Your Services, Your Contact Details, and Your Portfolio. We are going to build all of the sections with an interactive and attractive web design that
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences