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.React.jsWhy Use React?Before React, web development faced issues like slow DOM updates
7 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 methods to interact with the Document Object Model, or DOM. This package allows developers to access and modify the DOM. It is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient wa
3 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 ListsReact Lists are used to display a collection of similar data items like an array of objects and menu items. It allows us to dynamically render the array elements and display repetitive data.Rendering List in ReactTo render a list in React, we will use the JavaScript array map() function. We will ite
5 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 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. In this article, we'll explore ReactJS keys, understand their importance, how the
5 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.Stateless (before hooks)
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
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