How to use CssBaseLine Component in ReactJS ?
Last Updated :
17 Nov, 2023
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 application on top of the Theme. Material UI for React has this component available for us, and it is very easy to integrate.
Prerequisites:
Approach:
To add basic CSS styling for the React Elements we will be using the CssBaseLine component from the Material UI. We will first install the MUI core package from NPM and enclose the content within the CssBaseLine Component.
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 i @material-ui/core
Project Structure:

Project Structure
The updated dependencies in package.json file.
"dependencies": {
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@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-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Example 1: This example uses CssBaseLine Component from MUI to implement basic styling to the specific components.
Javascript
import React from "react" ;
import CssBaseline from "@material-ui/core/CssBaseline" ;
export default function App() {
return (
<div style={{ display: "block" , padding: 30 }}>
<h4>
How to use CssBaseline Component in ReactJS?
</h4>
<CssBaseline>
<p>Greetings from GeeksforGeeks</p>
<p>
These lines are within CssBaseline
Component
</p>
<p>Stay Safe and Healthy</p>
</CssBaseline>
</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:

Example 2: This example shows the same content on the web page without using CssBaseLine
Javascript
import React from "react" ;
export default function App() {
return (
<div style={{ display: "block" , padding: 30 }}>
<h4>
How to use CssBaseline Component in ReactJS?
</h4>
<p>Greetings from GeeksforGeeks</p>
<p>
These lines are without CssBaseline
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 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 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
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 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 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
How to Use and Style React Components in Gatsby?
Gatsby is a popular static site generator that leverages React for building user interfaces. React components play a crucial role in Gatsby, allowing developers to create reusable UI elements and manage the state effectively. This article explores how to use and style React Components in Gatsby. Ste
2 min read
How to create Class Component in React?
JavaScript syntax extension permits HTML-like code within JavaScript files, commonly used in React for defining component structure. It simplifies DOM element manipulation by closely resembling HTML syntax. JSX facilitates the creation of reusable UI building blocks, defined as JavaScript functions
2 min read
How to write comments in ReactJS ?
When working with ReactJS or any other programming language, making the code easy to understand is essential. One of the best ways to do this is by using comments. Comments are simple notes within the code that help to explain what is happening or why something was done in a specific way. To write c
3 min read
How To Use Checkboxes in ReactJS?
Checkboxes are essential UI components used in web applications that allow users to select one or more options from a list. React makes it simple to work with checkboxes, whether you're dealing with a single checkbox or a list of checkboxes. In this article, we will see how to use Checkboxes in Reac
2 min read
How to create Functional Components in React ?
To create a functional component in React, you define a JavaScript function that returns JSX. These components are stateless and rely on props for data input. Functional components are concise, easy to read, and can utilize React Hooks for managing state and side effects, making them a fundamental b
2 min read