![]() |
VOOZH | about |
Material-UI (MUI) is a popular React UI framework that provides ready-made components following Googleโs Material Design. It integrates well with Next.js to build responsive, modern web interfaces quickly.
To use the Material-UI with Next.js
First Let's start by creating a Next.js project.
Step 1: Initialize a nwe Next.js project using the following command:
npx create-next-app gfg-next-muiStep 2: Move to the Project directory
cd gfg-next-muiStep 3: Install Material-UI
To install the dependencies and save them in your package.json file, run:
npm install @mui/material @emotion/react @emotion/styled @emotion/serverIt will look like this.
๐ Project StructureThe updated dependencies in the package.json file are:
"dependencies": {
"@emotion/react": "^11.13.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.0",
"@mui/material": "^5.16.5",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18"
}Step 4: Modify the _document.js file. Configure the next app for server-side rendering using the Material UI and emotion library.
Step 5: Define Material-UI theme with custom primary, secondary, and error colors using createTheme from @mui/material/styles.
Create an src folder, add theme.js and createEmotionCache.js files as below
Step 5: Update the file /pages/_app.js with the below code
Step 6: Update the Home Component in /pages/index.js with the below code.
Steps to run the application: To run the app, type the following command in the terminal.
npm run devOutput:
๐ Image