React Rebass is a front-end framework that was designed keeping react in mind. In this article, we will know how to use CSS Grid in React rebass. CSS Grid is an important component that is required in each development.
CSS Grid is useful for arranging direct child elements without having to apply additional styles to them. Create a Box component extender that wraps other elements to apply a grid layout.
Syntax:
<Box sx={{ display:'grid', gridGap: 4 }}> CSS Grid</Box>Creating React Application & Installing Module:
Step 1: Create a React application using the following command.
npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command.
cd foldernameStep 3: Install React Rebass in your given directory.
npm i rebassProject Structure: It will look like the following.

Step to Run Application: Run the application from the root directory of the project, using the following command.
npm startExample 1: This is the basic example that shows how to use the CSS Grid.
import React from "react";
import { Box, Heading, Text } from "rebass";
const gfg = () => {
return (
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>React Rebass CSS Grid</h4>
<Box
sx={{
display: 'grid',
gridGap: 4,
}}>
<Heading p={3} color='red' bg='green'>
Grid
</Heading>
<Text p={3} color='white' bg='blue'>
GeeksforGeeks
</Text>
</Box>
</div>
);
};
export default gfg;
Output:

Example 2: In this example, we will know how to make a column-based grid.
import React from "react";
import { Box, Heading, Text } from "rebass";
const gfg = () => {
return (
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>React Rebass CSS Grid</h4>
<Box
sx={{
display: 'grid',
gridGap: 4,
gridTemplateColumns: 'repeat(auto-fit, minmax(128px, 1fr))',
}}>
<Heading p={3} color='red' bg='green'>
Grid
</Heading>
<Text p={3} color='white' bg='blue'>
GeeksforGeeks
</Text>
</Box>
</div>
);
};
export default gfg;
Output:
