How to use ScopedCssBaseline Component in ReactJS ?
Last Updated :
20 Nov, 2023
ScopedCssBaseline component helps in applying baseline only to the children. Material UI for React has this component available for us, and it is very easy to integrate. We can use the ScopedCssBaseline Component in ReactJS using the following approach.
Prerequisites:
Approach:
- Include Necessary Components:
- Start by bringing in the essential elements from the Material-UI library, such as the ScopedCssBaseline component.
- Construct the App Component:
- Construct a functional component, like 'App,' to function as the core element of your React application.
- Enclose Targeted Content:
- Envelop the JSX content requiring isolation by enclosing it within the ScopedCssBaseline component. This guarantees that any styles applied remain confined to this specific section, avoiding interference with global styles.
- Apply Styles:
- Take advantage of the encapsulated area to apply distinct styles without the concern of impacting the broader application. This method proves especially valuable for preserving style uniformity within a designated part of your React application.
Steps to Create React Application And Installing Module:
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 material-ui modules using the following command.
npm install @material-ui/core
Project Structure:
Project StructureThe updated dependencies in package.json file will look like:
"dependencies": {
"@material-ui/core": "^4.12.4",
"react": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example 1: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.Â
JavaScript
import React from "react";
import ScopedCssBaseline
from "@material-ui/core/ScopedCssBaseline";
export default function App() {
return (
<div style={{ display: "block", padding: 30 }}>
<h4>How to use ScopedCssBaseline Component in ReactJS?</h4>
<ScopedCssBaseline>
<p>Greetings from GeeksforGeeks</p>
<p>
These lines are within
ScopedCssBaseline Component
</p>
<p>Stay Safe and Healthy</p>
</ScopedCssBaseline>
</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/, you will see the following output:

Now if we write the same example but without using the ScopedCssBaseline Component, the following will be the result.
Example 2: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.Â
JavaScript
import React from "react";
export default function App() {
return (
<div style={{ display: "block", padding: 30 }}>
<h4>How to use ScopedCssBaseline Component in ReactJS?</h4>
<p>Greetings from GeeksforGeeks</p>
<p>
These lines are without
ScopedCssBaseline Component
</p>
<p>Stay Safe and Healthy</p>
</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/, you will see the following output.
Similar Reads
How to use TreeView Component in ReactJS ?
Explore the functionality of ReactJS's TreeView component, a powerful tool for seamlessly navigating and displaying hierarchical structures in web applications. This comprehensive guide delves into the integration process, empowering you to represent complex data relationships in an organized and us
2 min read
How to use NoSsr Component in ReactJS?
NoSsr purposely removes components from the subject of Server Side Rendering (SSR). Material UI for React has this component available for us, and it is very easy to integrate. We can use the NoSsr Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReactJSMaterial UISteps
2 min read
How to use XGrid Component in ReactJS ?
An XGrid Component is a Commercial version of the MaterialUI Component. It provided more enhanced features over the community DataGrid Component like column resizing, column reordering, pagination over 100 rows, etc. A DataGrid Component helps in displaying the information in a grid-like format of r
3 min read
How to use Link Component in React JS?
Material-UI provides a set of components that can be seamlessly integrated with React to create visually appealing and functional navigation elements. The Link component allows you to easily customize anchor elements with our own theme colors and typography styles. Material UI for React has this com
2 min read
How to use Paper Component in ReactJS ?
In Material Design, the physical properties of paper are translated to the screen. Material UI for React has this component available for us and it is very easy to integrate. We can use the Paper Component in ReactJS using the following approach. Prerequisites:React JSMaterial UIApproachTo use Paper
2 min read
How to use Portal Component in ReactJS ?
The portal component renders its children into a new subtree outside the current DOM hierarchy. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Portal Component in ReactJS using the following approach.Prerequisites:NodeJS or NPMReact JSMate
2 min read
How to use Avatar Component in ReactJS?
Avatars are found throughout material design with uses in everything from tables to dialog menus. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Avatar Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReactJSSt
2 min read
How to use DataGrid Component in ReactJS ?
A DataGrid Component helps in displaying the information in a grid-like format of rows and columns. Material UI for React has this component available for us, and it is very easy to integrate. We can use the following approach in ReactJS to use DataGrid Component.Creating React Application And Insta
2 min read
How to use Divider Component in ReactJS?
A divider is a thin line that groups content in lists and layouts. To use Diveder Component in React JS we can either create one or we can also import it from other UI libraries like Bootstrap, MaterialUI, etc. PrerequisitesReact JSMaterial UINode.js and NPMTable of Content Creating Divider componen
3 min read
How to use CssBaseLine Component in ReactJS ?
In React JS, A CssBaseline component is a collection of HTML elements and attribute style-normalizations. At the <head> of our document, it is added as CSS reset. This component is used to add some basic styling to our application like box-sizing, background color, etc like CSS reset for our a
3 min read