React Bootstrap Grid is like the maestro of web page layouts in React Bootstrap. It's your go-to buddy for crafting designs that look good and adapt seamlessly across devices. From straightforward single-column setups to intricate multi-column arrangements, this tool's got the flexibility and power to make it happen.
There are two main approaches to implement React Bootstrap Grid:
Using Grid component
The Grid component is the main component for creating a grid layout.
- The grid is divided into 12 columns by default.
- Columns must add up to 12 for each row.
- Breakpoints are used to adjust layouts for different screen sizes (xs, sm, md, lg, xl).
- Offsets can be used to create spacing between columns.
- Ordering can be used to rearrange column positions on different screen sizes.
It takes a number of props that can be used to control the layout of the grid. Here are some of the most important props:
- container: Determines whether the grid should have a fixed width or a fluid width. A fixed-width grid will always have the same width, regardless of the screen size. A fluid-width grid will adjust its width to fit the available space on the screen.
- columns: Specifies the number of columns in the grid. The number of columns can be any number from 1 to 12.
- gutter: Specifies the width of the gutter between the columns. The gutter is measured in pixels.
- className: Used to add custom CSS classes to the grid.
Using the Row and Col components
The Row and Col components are used to create rows and columns within the grid. The Row component defines a new row in the grid, and the Col component defines a column within that row.
The Col component takes a number of props that can be used to control the layout of the column. Here are some of the most important props:
- xs, sm, md, lg, xl: Props like xs and sm specify column spans for different screen sizes (e.g., phones and tablets).
- offset-xs, offset-sm, offset-md, offset-lg, offset-xl: These props determine the column offset on various screen sizes, like offset-xs for extra-small screens (phones) and offset-sm for small screens (tablets), and so forth.
Fluid Container
Use <Container fluid /> for width: 100% across all viewport and device sizes.
Example: Below is the code example of the Fluid Container
JavaScript
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
function ExampleContainer() {
return (
<Container fluid>
<Row>
<Col className="bg-secondary">A fluid container</Col>
</Row>
</Container>
);
}
export default ExampleContainer;
Output:

Auto-layout columns
If column widths are not explicitly defined, the Col component will display columns of equal width.
Example: Below is the code example of the Auto-layout columns
JavaScript
import Container
from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
function Example1() {
return (
<Container>
<Row>
<Col className='bg-success'>
1 of 2
</Col>
<Col className='bg-warning'>
2 of 2
</Col>
</Row>
<Row>
<Col className='bg-warning'>
1 of 3
</Col>
<Col className='bg-success'>
2 of 3
</Col>
<Col className='bg-warning'>
3 of 3
</Col>
</Row>
</Container>
);
}
export default Example1;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output:

Setting one column width
Flexbox grid columns with auto-layout enable you to define the width of a single column, leading to automatic resizing of adjacent columns. This can be achieved using predefined grid classes, grid mixins, or inline widths. Importantly, the width of the center column influences the resizing of the surrounding columns.
Example: Below is the code example of the Setting one column width
JavaScript
function Example2() {
return (
<Container>
<Row>
<Col className='bg-primary'>
1 of 3
</Col>
<Col xs={6}
className='bg-secondary'>
2 of 3 (wider)
</Col>
<Col>3 of 3</Col>
</Row>
<Row>
<Col className=''>
1 of 3
</Col>
<Col xs={5}
className='bg-primary'>
2 of 3 (wider)
</Col>
<Col
className='bg-warning'>
3 of 3
</Col>
</Row>
</Container>
);
}
export default Example2;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output:

Variable width content
You can set the column value to auto to size columns based on the natural width of their content.
Example: Below is the code example of the Variable width content
JavaScript
import Container
from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
function Example3() {
return (
<Container>
<Row className="justify-content-md-center">
<Col xs lg="2"
className='bg-primary'>
1 of 3
</Col>
<Col md="auto"
className='bg-warning'>
2 of 3 (variable content) Lorem ipsum,
dolor sit amet consectetur adipisicing
elit. Aperiam eaque ex iure odio illo
sed, praesentium delectus qui ducimus
unde doloremque temporibus deleniti
accusantium ratione esse dicta illum
recusandae nemo?
</Col>
<Col xs lg="2"
className='bg-secondary'>
3 of 3
</Col>
</Row>
</Container>
);
}
export default Example3;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output

Responsive grids
Using the Col component, you can designate column widths for six breakpoint sizes (xs, sm, md, lg, xl, and xxl). At each breakpoint, you have the option to define the number of columns to span. Alternatively, you can utilize the prop `<Col lg={true} />` for automatic layout widths.
- Multiple breakpoints can be added to create different grids depending on the screen size.
- The Col breakpoint props have the form prop form: {span: number, order: number, offset: number} for specifying offsets and ordering effects.
- Order property can be used to control the visual order of the content.
Example: Below is the code example of the Responsive grids
JavaScript
function Example5() {
return (
<Container>
<Row>
<Col sm={8}
className='bg-primary'>
sm=8
</Col>
<Col sm={4}
className='bg-secondary'>
sm=4
</Col>
</Row>
<Row>
<Col sm
className='bg-secondary'>
sm=true
</Col>
<Col sm
className='bg-warning'>
sm=true
</Col>
<Col sm
className='bg-primary'>
sm=true
</Col>
<Col sm
className='bg-secondary'>
sm=true
</Col>
</Row>
</Container>
);
}
export default Example5;
Step to Run Application: Run the application using the following command from the root directory of the project
npm start
Output

Setting column widths in Row
The Row component allows you to define column widths for six breakpoint sizes (xs, sm, md, lg, xl, and xxl). At each breakpoint, you can specify the number of columns that will be placed adjacent to each other. Additionally, you have the option to set the columns to their natural widths by using the "auto" value. It's important to note that Row column widths will take precedence over Col widths set at lower breakpoints when viewed on larger screens. For example, the size specified by `<Col xs={6} />` will be overridden by `<Row md={4} />` on medium and larger screens.
Example: Below is the code example of the setting column widths in row
JavaScript
import Container
from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
function Example4() {
return (
<Container>
<Row xs={2} md={4} lg={6}>
<Col className='bg-warning'>
1 of 2
</Col>
<Col>
2 of 2
</Col>
</Row>
<Row xs={1} md={2}>
<Col className='bg-primary'>
1 of 3
</Col>
<Col className='bg-warning'>
2 of 3
</Col>
<Col className='bg-secondary'>
3 of 3
</Col>
</Row>
<Row xs="auto">
<Col className='bg-warning'>
1 of 3
</Col>
<Col className='bg-secondary'>
2 of 3
</Col>
<Col className='bg-primary'>
3 of 3
</Col>
</Row>
</Container>
);
}
export default Example4;
Step to Run Application: Run the application using the following command from the root directory of the project
npm start
Output

Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. "Hello, World!" Program in ReactJavaScriptimport React from 'react'; function App() {
6 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides DOM-specific methods to interact with and manipulate the Document Object Model (DOM), enabling efficient rendering and management of web page elements. ReactDOM is used for: Rendering Components: Displays React components in the DOM.DOM Manipulation: Al
2 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsIn lists, React makes it easier to render multiple elements dynamically from arrays or objects, ensuring efficient and reusable code. Since nearly 85% of React projects involve displaying data collectionsâlike user profiles, product catalogs, or tasksâunderstanding how to work with lists.To render a
4 min read
React FormsIn React, forms are used to take input from users, like text, numbers, or selections. They work just like HTML forms but are often controlled by React state so you can easily track and update the input values.Example:JavaScriptimport React, { useState } from 'react'; function MyForm() { const [name,
4 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. When rendering a list, you need to assign a unique key prop to each element in th
4 min read
Components in React
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects