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 Structure
The 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 update the State of a component in ReactJS ?
To display the latest or updated information, and content on the UI after any User interaction or data fetch from the API, we have to update the state of the component. This change in the state makes the UI re-render with the updated content. Prerequisites: NPM & Node.jsReact JSReact StateReact
3 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
ReactJS Onsen UI Segment Component
ReactJS Onsen-UI is a popular front-end library with a set of React components that are designed to developing HTML5 hybrid and mobile web apps in a beautiful and efficient way. Segment Component allows the user to toggle between a different number of options in a row. We can use the following appro
2 min read
How to use HOCs to reuse Component Logic in React ?
In React, making reusable components keeps your code neat. Higher-order components (HOCs) are a smart way to bundle and reuse component logic. HOCs are like magic functions that take a component and give you back an upgraded version with extra powers or information. HOCs can be implemented in a few
4 min read
How to put ReactJS component inside HTML string ?
Putting the React JS component inside the HTML library is not recommended and may lead to conflict in React lifecycle methods. But it can be done by parsing the HTML String into DOM using the html-to-react module. html-to-react is a lightweight library that is responsible for converting raw HTML to
3 min read
How to Map Data into Components using ReactJS?
Mapping data in react js component is a comman practice to render the lists and repeating elements. In this article, we will have a users data and we will map it to react components to display the users information in the react app Prerequisites:React JSNodejs and npmJavaScript Array mapApproachTo m
3 min read
How to create components in ReactJS ?
Components in React JS is are the core of building React applications. Components are the building blocks that contains UI elements and logic, making the development process easier and reusable. In this article we will see how we can create components in React JS. Table of Content React Functional C
3 min read