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
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How to use AppBar Component in Material UI ?
Next article icon

How to use AppBar Component in Material UI ?

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

Using AppBar component in Material UI provides a flexible and customizable navigation bar for your web applications. The App Bar displays information and actions relating to the current screen. Material UI for React has this component available for us and it is very easy to integrate.

Prerequisites

  • React JS
  • Material UI

Approach

To use AppBar Component in Material UI in React JS, we will create a top bar or Nav consisting of the AppBar component, Toolbar, IconButton, MenuIcons and Typegraphy components to implement a Nav along with functionality like logins, dropdown etc.

We can use the AppBar Component in ReactJS using the following approach.

Steps to Create React Application

Step 1: Create a React application using the following command:

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command:

cd foldername

Step 3: After creating the ReactJS application, Install the MUI modules using the following command:

npm i @mui/material @mui/icons-material @emotion/styled

Project Structure

It will look like the following.

Dependencies list in package.json

{
"dependencies": {
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.14",
"@mui/material": "^5.14.14",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.17.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
}

Example 1: In this example, we will create a basic app bar application, that will have a menu icon and some text.  

JavaScript
// Filename - App.js  import * as React from 'react'; import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import IconButton from '@mui/material/IconButton'; import MenuIcon from '@mui/icons-material/Menu';  export default function ButtonAppBar() {     return (         <AppBar>             <Toolbar>                 <IconButton                     size="large"                     edge="start"                     color="inherit"                     aria-label="menu"                     sx={{ mr: 2 }}                 >                     <MenuIcon />                 </IconButton>                 <Typography variant="h6"                     component="div" sx={{ flexGrow: 1 }}>                     Geeksforgeeks                 </Typography>                 <Button color="inherit">Logout</Button>             </Toolbar>         </AppBar>     ); } 

Step to Run Application: Run the application using the following command from the root directory of the project.

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output.

Example 2: In this example, we will create a simple app bar application with a toggle-able menu.

JavaScript
// Filename - App.js  import * as React from 'react'; import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import IconButton from '@mui/material/IconButton'; import MenuIcon from '@mui/icons-material/Menu'; import Switch from '@mui/material/Switch'; import FormControlLabel from '@mui/material/FormControlLabel'; import FormGroup from '@mui/material/FormGroup';  export default function MenuAppBar() {     const [auth, setAuth] = React.useState(true);      const handleChange = (event) => {         setAuth(event.target.checked);     };      return (         <Box sx={{ flexGrow: 1 }}>             <FormGroup>                 <FormControlLabel                     control={                         <Switch                             checked={auth}                             onChange={handleChange}                             aria-label="login switch"                         />                     }                     label={auth ? 'Hide Menu' : 'Show Menu'}                 />             </FormGroup>             <AppBar position="static">                 <Toolbar>                     <IconButton                         size="large"                         edge="start"                         color="inherit"                         aria-label="menu"                         sx={{ mr: 2 }}                     >                         <MenuIcon />                     </IconButton>                     <Typography variant="h6" component="div"                         sx={{ flexGrow: 1 }}>                         Geeksforgeeks                     </Typography>                     {auth && (                         <div style={{ display: 'flex', gap: '10px' }}>                             <Typography>Contact US</Typography>                             <Typography>About US</Typography>                         </div>                     )}                 </Toolbar>             </AppBar>         </Box>     ); } 


Steps to run the application:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output.

Reference: https://mui.com/material-ui/react-app-bar/


Next Article
How to use AppBar Component in Material UI ?

G

gouravhammad
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • Web technologies
  • React-Questions

Similar Reads

    How to use Box Component in Material UI ?
    The Material UI Box component serves as a wrapper component for most of the CSS utility needs. Material UI for React has this component available for us and it is very easy to integrate. We can use the Box component in ReactJS using the following ways. Prerequisites to use MUI Box ComponentReact JSR
    2 min read
    How to use Button Component in Material UI ?
    Buttons allow users to take actions, and make choices, with a single tap. Material UI for React has this component available for us and it is very easy to integrate. We can use the Button component in ReactJS using the following approach. Creating React Application And Installing Module: Step 1: Cre
    2 min read
    How to use Breadcrumbs Component in Material UI ?
    Breadcrumbs are list of links that display the page location within a website or application. They allow users to make selections from a range of values. Material UI for React has this component available for us, and it is very easy to integrate. In this article we will see how we can integrate and
    2 min read
    How to use Fab Component in Material UI ?
    Fab stands for Floating Action Button is which appears in front of all screen content, typically as a circular shape with an icon in its center. Material UI for React has this component available for us and it is very easy to integrate. It can be used to turn an option on or off. We can use the Fab
    2 min read
    How to use Slider Component in Material UI ?
    Sliders allow users to make selections from a range of values. Material UI for React has this component available for us and it is very easy to integrate. We can use the Slider Component in ReactJS using the following approach:Creating React Application And Installing Module:Step 1: Create a React a
    2 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