Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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 List Component in ReactJS?
Next article icon

How to create Accordion in ReactJS ?

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

Accordions contain creation flows and allow lightweight editing of an element. Material UI for React has this component available for us, and it is very easy to integrate. We can create it in React using the following approach.

Approach to create Accordion in React JS

To create accordion in react we will

  • use the MUI Accordion component.
  • use the expand icons, AccordionSummary and AccrodionDetail component from MUI along with related content for a complete working accordion.
  • Style the accrodion using CSS and inline styling.

Steps to Create the React Application And Installing Module

Step 1: Initialize and setup the react app using the CRA command.

Step 2: After creating the ReactJS application, Install the material-ui modules using the following command.

npm i @material-ui/core
npm i @material-ui/icons

The updated dependencies in package.json file will look like:

"dependencies": {
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
}

Example: This example demonstrate how to create accordion in react with the help of MUI accordion compoenet. Now write down the following code in the App.js file.

JavaScript
// Filename - App.js  import React from "react"; import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; import Accordion from "@material-ui/core/Accordion"; import AccordionDetails from "@material-ui/core/AccordionDetails"; import Typography from "@material-ui/core/Typography"; import AccordionSummary from "@material-ui/core/AccordionSummary";  export default function App() {     return (         <div style={{}}>             <h4>How to create Accordion in ReactJS?</h4>             <Accordion style={{ width: 400 }}>                 <AccordionSummary                     expandIcon={<ExpandMoreIcon />}                     aria-controls="panel1a-content">                     <Typography                         style={{                             fontWeight: 10,                         }}>                         Accordion Demo                     </Typography>                 </AccordionSummary>                 <AccordionDetails>                     <Typography>                         Greetings of the day :)                     </Typography>                 </AccordionDetails>             </Accordion>         </div>     ); } 

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


Next Article
How to use List Component in ReactJS?
author
gouravhammad
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • React-Questions

Similar Reads

  • How to create Tabs in ReactJS ?
    Tabs make it easy to explore and switch between different views. Material UI for React has this component available for us and it is very easy to integrate. We can use Tabs Component in ReactJS using the following approach. Prerequisites:NPM & Node.jsReact JSMaterial UIwe have these approaches t
    4 min read
  • How to create a Read More component in ReactJS?
    Creating a Read More component in React JS refers to hiding and displaying the text content on the page. It can be achieved by setting the state variable and display the content accordingly. PrerequisitesNode.JS and npmReact JSReact JS useState() hookApproachTo create a Read More component in React
    3 min read
  • How to create Menu Item Component in ReactJS ?
    React JS is a popular JavaScript library used for building user interfaces. It provides a component-based architecture that allows developers to create reusable UI elements. Material UI for React has this component available for us and it is very easy to integrate. We can use Menu Component in React
    2 min read
  • How to create Popup box in React JS ?
    Popup boxes, also known as modal or dialog boxes, are common UI elements used to display additional content or interactions on top of the main page. Creating a popup box in React can be achieved using various approaches, including libraries or custom implementations. We will use the Reactjs-popup li
    2 min read
  • How to use List Component in ReactJS?
    Lists are continuous, vertical indexes of text or images. Material UI for React has this component available for us, and it is very easy to integrate. We can use the List Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReactJSSteps to Create the React Application And In
    2 min read
  • How to use Container Component in ReactJS?
    The container centers your content horizontally. It's the most basic layout element. Material UI for React has this component available for us and it is very easy to integrate. We can use the Container component in ReactJS using the following approach. Creating React Application And Installing Modul
    1 min read
  • How to use Zoom Component in ReactJS?
    Zoom Component adds a Zoom animation to a child element or component. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Zoom Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReact JSMaterial UIApproach:The React c
    2 min read
  • How to create a Responsive Carousel in React JS ?
    A carousel, often seen in web and mobile applications, is a user interface component used to display a set of content items such as images or text in a rotating manner. It allows users to view multiple items within a limited space by scrolling horizontally or vertically through the content. In this
    2 min read
  • How to use Grow Component in ReactJS?
    Grow Component in ReactJS adds a Grow animation to a child element or component. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Grow Component in ReactJS using the following approach. PrerequisitesReact JSMaterial UIApproachTo implement th
    2 min read
  • How to use Collapse Component in ReactJS ?
    ReactJS, a popular JavaScript library for building user interfaces, provides developers with a rich set of components to create interactive and dynamic web applications. One such component is the Collapse component, which allows you to hide and reveal content based on user interaction. In this artic
    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