Author avatar

Gaurav Singhal

What to Do if Your React and Bootstrap Columns Aren't Working Together

Gaurav Singhal

  • Nov 10, 2020
  • 3 Min read
  • Nov 10, 2020
  • 3 Min read
Web Development
Client-side Frameworks
Front End Web Development


Using native Bootstrap in a React project can often cause errors due to an incorrect initial setup. In order to make Bootstrap columns work together, you need to make sure that you have correctly imported and required the CSS file containing styles for row and col classes. Otherwise, your Bootstrap rows and columns will act like regular <div> without the required styles to support their intended structure. In this guide, you'll learn how to correctly set up React with Bootstrap so that Bootstrap columns work correctly together.


Create a new React project using the following command:

1npx create-react-app react-bootstrap-columns

Inside the root folder, install Bootstrap via npm using the following command:

1npm i bootstrap

Next, modify the App.js as shown below.

1import './App.css';
3function App() {
4  return (
5    <div className="App">
6      <div className="row">
7        <div className="col">
8          <div className="box">Col 1/3</div>
9        </div>
10        <div className="col">
11          <div className="box">Col 2/3</div>
12        </div>
13        <div className="col">
14          <div className="box">Col 3/3</div>
15        </div>
16      </div>
17    </div>
18  );
21export default App;

The App component simply outputs three nested <div> containing display text inside a parent <div>. The parent <div> is a Bootstrap row, aligning all child elements in a row. Since the three children <div> have the col class and are direct children of the row, each is expected to occupy a third of the width of the entire row next to each other as equally spaced columns. Add some simple styles inside App.css as shown below.

2  max-width: 100vw;
3  overflow-x: hidden;
6  margin: 10px;
7  padding: 20px;
8  border: 2px solid salmon;
9  text-align: center;
10  color: salmon;

In contrary to the expected outcome, the three bordered boxes appear as regular <div> spanning over an entire row stacked on top of each other instead of being aligned as columns. This is because the default Bootstrap styles for row and col classes are not applied even though Bootstrap is installed in your project. The App component simply loads the JSX without any declared styles for the classes used. These styles are present inside a CSS file inside the node_modules folder where the entire Bootstrap library is installed. Import this file on the top of your App component as shown below.

1import 'bootstrap/dist/css/bootstrap.min.css';

Now the entire styles come back, with the three columns stacked next to each other in a single row. The font-family of the text inside the box also changes. This is because it inherited some styles from Bootstrap's CSS file.


It's important to understand how different UI libraries let you import the required stylesheet for their components. Working with Bootstrap by either downloading the files or using CDNs may not produce the error because the styles are shipped to your components via the <script> or <link> tags. But when using it via npm, you need to import the stylesheet as a module inside every component where you intend to use its native classes. The same pattern can be extended to libraries such as React Bootstrap, Reactstrap, etc.