Important Update
The Guide Feature will be discontinued after December 15th, 2023. Until then, you can continue to access and refer to the existing guides.
Author avatar

Chris Parker

How to Integrate Bootstrap with ReactJS

Chris Parker

  • Jan 10, 2020
  • 16 Min read
  • Jan 10, 2020
  • 16 Min read
Web Development


We'll focus on the following skills in this guide:

  1. Building UI in a React-based web app and using Bootstrap's look and feel.
  2. Using reactstrap to develop a React app for listing contacts.

React is the most commonly used JS framework for developing interactive web apps. But since it is a view library, it does not come with techniques to build designs that are responsive and very intuitive. In order to overcome this, we can use Bootstrap, which is a front-end design framework.

Why Bootstrap Components Cannot Be Included with React

Adding a HTML tag like <link rel=”stylesheet”/> to an HTML file like index.html is an easy task, but it’s not the same when adding Bootstrap to React. The reason is that Bootstrap relies on jQuery to run particular user interface components. And jQuery manipulates the DOM directly, which contradicts the declarative approach of React. We can use the simple vanilla Bootstrap stylesheet for web applications if the requirement is limited to a receptive 12-column grid or components that do not involve jQuery. Otherwise, there are different libraries that can enable the use of Bootstrap along with React.

We'll examine both methods so that we can choose which one is best suited for a given scenario. We'll focus on the implementation details for integrating Bootstrap with React app.

How to Setup Bootstrap Stylesheet with React

We will be using Create React App CLI to get started with our React project. It does not require any configuration to start.

The following commands can be used install Create React App and to start the server in development mode:

1$ create-react-app my-bootstrap-react-app
2$ cd my-bootstrap-react-app
3$ npm start

The directory structure generated by Create React App is as below:

2├── package.json
3├── public
4│   ├── favicon.ico
5│   ├── index.html
6│   └── manifest.json
8├── src
9│   ├── App.css
10│   ├── App.js
11│   ├── App.test.js
12│   ├── index.css
13│   ├── index.js
14│   ├── logo.svg
15│   └── registerServiceWorker.js
16└── yarn.lock

The next step is to take the latest Bootstrap library from its official website. The downloaded package consists of the compiled as well as minimized versions of JavaScript and CSS files. There is a grid-specific stylesheet as well for apps that just need to make use of grids. The next step is to make a new folder for CSS in public, copy bootstrap.min.css file there, and then add the required code in public/index.html to link it.

2<link rel="stylesheet" href="css/bootstrap.min.css">

Another way is to use a CDN to fetch the minimized CSS:

1<link rel="stylesheet" href= "">

How to Use Regular Bootstrap Classes With React

We can use Bootstrap classes with JSX code after the Bootstrap stylesheet has been added to a React app. In order to verify this, we'll copy some random sample code from the Bootstrap demo site:

1import React from "react";
2import {render} from "react-dom";
3import Forms from "./Forms";
4import NavBar from "./NavBar";
6const App = () => (
7  <div>
8    <NavBar />
9    <br />
10    <div className="container">
11      <div className="row">
12        <div className=" col-lg-offset-4 col-lg-8">
13          <Forms />
14        </div>
15      </div>
16    </div>
17  </div>
20render(<App />, document.getElementById("root"));

It would be really nice if the Bootstrap classes could be imported as React components to make the best use of React. For example, we could have grid, row and Ccolumn components to organize the page instead of the HTML classes as shown below:

1<!--Bootstrap Using HTML styles/classes-->
3<div class="container">
4  <div class="row">
5    <div class="col-sm">
6      Col 1 of 3
7    </div>
8    <div class="col-sm">
9      Col 2 of 3
10    </div>
11    <div class="col-sm">
12      Col 3 of 3
13    </div>
14  </div>
17<!--Bootstrap Using React-based Components-->
20  <Row>
21      <Col sm>
22        Col 1 of 3
23    </Col>
24    <Col sm>
25        Col 2 of 3
26    </Col>
27     <Col sm>
28        Col 3 of 3
29    </Col>
30  </Row>

Luckily, there is no need to implement our own library to make this possible, as there are libraries already available. Let’s explore a few of these.

Using Third-party Libraries for React and Bootstrap

There are some libraries that attempt to develop an implementation of Bootstrap that is specific to React that will allow us to use JSX components as well as work with Bootstrap styles. Following are some of the popular Bootstrap modules that can be used with React projects.

  1. React-Bootstrap is amongst the top libraries for adding Bootstrap components to React projects. But its current implementation is targeted for Bootstrap v3 and not the latest version.

  2. reactstrap is another library which enables us to use Bootstrap components in a React app. In contrast to React-Bootstrap, reactstrap is developed to be used with the latest version of Bootstrap. The reactstrap implementation has components for forms, buttons, tables, layout grids, and navigation. It is currently in development, but provides a nice alternative for developing apps with React and Bootstrap together.

There are some alternatives like React-UI and some domain-specific modules like CoreUI-React, React-bootstrap-table available on GitHub that deliver extensive utilities to develop some cool UI for apps using React.

In this guide, we'll focus on reactstrap since it is the most popular and uses the latest Bootstrap version.

How to Set Up Reactstrap Library

To get started, we install the reactstrap library using npm:

1npm install --save reactstrap@next

Now, the relevant components from the module can be imported as below:

1import { Container, Row, Col} from 'reactstrap';

At this stage, the library will not work as expected since it does not include Bootstrap CSS. We'll need to add it manually as shown below:

1npm install --save bootstrap

Next step is to import Bootstrap CSS in our src/index.js file:

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

Understanding Bootstrap Grid

Bootstrap is developed with a responsive, mobile first grid system that enables the use of 12 columns per page. We'll need to import the Container, Row and Col components in order to use the grid. The Container has a fluid attribute that alters a fixed-width layout to a full-width layout. It essentially adds the .container-fluid bootstrap class to the grid. The Col component can be configured to work with attributes like xs, md, sm and lg that work the same way as the col-* classes in Bootstrap, e.g., <Col xs=”6”> </Col>. Another way to implement this is by passing an object to the props with optional attributes like size, order, and offset. The size attribute denotes how many columns are there in the grid, while order enables us to arrange the columns and works with values from 1 to 12. The columns can be moved to the right by using the offset property. The following code elaborates a few of the features of Grid in reactstrap:

1import React, {Component} from "react";
2import { render } from "react-dom";
3import { Row, Col, Container} from "reactstrap";
4import "bootstrap/dist/css/bootstrap.css";
5import "./App.css";
7class App extends Component {
8  render() {
9    return (
10      <div>
11		<Container>
12          <Row>
13            <Col>
14              <Box>.col </Box>
15            </Col>
16          </Row>
17          <Row>
18            <Col xs="4">
19              <Box> .col-4 </Box>
20            </Col>
22            <Col xs="4">
23              <Box> .col-4 </Box>
24            </Col>
25          </Row>
27          <Row>
28            <Col xs="6">
29              <Box> .col-6 </Box>
30            </Col>
32            <Col xs="6">
33              <Box> .col-6 </Box>
34            </Col>
35            <Col xs="6">
36              <Box>.col-6 </Box>
37            </Col>
38          </Row>
39          <Row>
40            <Col>
41              <Box>.col </Box>
42            </Col>
43            <Col>
44              <Box>.col </Box>
45            </Col>
46            <Col>
47              <Box> .col </Box>
48            </Col>
49            <Col>
50              <Box>.col </Box>
51            </Col>
52          </Row>
53          <Row>
54            <Col xs="3">
55              <Box> .col-3 </Box>
56            </Col>
57            <Col xs="auto">
58              <Box>.col-auto is used for dynamic content</Box>
59            </Col>
60            <Col xs="3">
61              <Box> .col-3 </Box>
62            </Col>
63          </Row>
64          <Row>
65            <Col sm={{ size: 4, order: 4, offset: 2 }}>
66              <Box> .col-sm-4 .col-sm-order-4 .col-sm-offset-4 </Box>{" "}
67            </Col>
68          </Row>
69          <Row>
70            <Col sm="12" md={{ size: 6, offset: 3 }}>
71              <Box> .col-sm-10 .col-md-4 .col-md-offset-5 </Box>
72            </Col>
73          </Row>
74        </Container>
75      </div>
76    );
77  }
80export default App;
81const Box = props => <div className="box">{props.children} </div>;
82render(<App />, document.getElementById("root"));

Using Bootstrap Components With React

Now that we are familiar with reactstrap and how it works, there are numerous components of Bootstrap 4 that can be used with React using reactstrap. We'll look at few of the important components in this guide.

Navigation Bar

reactstrap Navbars can be used for navigation bars and provide responsiveness. To organize the navigation links more efficiently, a Navbar consists of subcomponents like Nav, NavItem, NavbarBrand, etc . A responsive Navbar can created by adding a <NavbarToggler> inside our <Navbar> component and then wrapping <NavItems> into a <Collapse> component. We'll look at the following code to see how the Navbar component and React state can be used to save the toggle data;:

1export default class NavBarExample extends React.Component {
2  constructor(props) {
3    super(props);
4    this.toggleOpenState = this.toggleOpenState.bind(this);
5    this.state = {
6      isOpen: false
7    };
8  }
9  toggleOpenState() {
10    this.setState({
11      isOpen: !this.state.isOpen
12    });
13  }
14  render() {
15    return (
16      <div>
17        <Navbar color="#ffffff" light expand="md">
18               <NavbarBrand href="/">
19                This is a Navbar Demo
20            	</NavbarBrand>
21               {/* Below, we'll add toggler for auto-collapse */}
22          		<NavbarToggler onClick={this.toggleOpenState} />
23          		<Collapse isOpen={this.state.isOpen} navbar>
25              {/*Pull towards left */}
26            <Nav className="ml-auto" navbar>
27                <NavItem>
28                    <NavLink href="/link/">
29                        Left Navigation Link
30                    </NavLink>
31                </NavItem>
32            </Nav>
34            {/* Pull towards right */}
35            <Nav className="mr-auto" navbar>
36              <UncontrolledDropdown nav inNavbar>
37                <DropdownToggle nav caret>
38                  Chris
39                </DropdownToggle>
40                <DropdownMenu >
41                  <DropdownItem>
42                    My Account
43                  </DropdownItem>
44                  <DropdownItem>
45                    Page Settings
46                  </DropdownItem>
47                  <DropdownItem divider />
48                  <DropdownItem>
49                    Log Out
50                  </DropdownItem>
51                </DropdownMenu>
52              </UncontrolledDropdown>
53            </Nav>
54          </Collapse>
55        </Navbar>
56      </div>
57    );
58  }

Modal Window

The reactstrap Modal component can be used for generating a Bootstrap modal with a header, body, and footer. A modal component can be used with some props and callbacks to have the window interactive and also to have it closable. To decide whether the modal should be visible or not, the isOpen property is used. The toggle callback is used to switch the value of isOpen in the component. There are few more props that are used to animate the transitions. The available callbacks include onEnter, onExit, onOpened, and onClosed:

1{/*To open the modal window, needs to be true, which is generally set by an "onClick" event */}
2{/* toggleModal updates state of "show" to false onClose*/}
4<Modal isOpen={} toggle={this.toggleModal} >
6    <ModalHeader toggle={this.toggle}>
7        Modal title
8    </ModalHeader>
10    <ModalBody>
11        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper tristique suscipit. In ultrices sagittis iaculis. Maecenas porttitor elit eget neque molestie, id sodales diam consectetur. Fusce cursus justo quis eros commodo pellentesque. Aenean eget egestas augue Vivamus sit amet rhoncus lorem, vel pulvinar tellus. 
12    </ModalBody>
13    <ModalFooter>
14        <Button color="pri" onClick={this.toggle}>Click on Me!</Button>{' '}
15        <Button color="sec" onClick={this.toggle}>Cancel</Button>
16     </ModalFooter>


A reactstrap form can be inline or horizontal. The input element is rendered by an Input component. Multiple Input components can be wrapped into a FormGroup for state validation, appropriate spacing, and to use other FormGroup features. To set any label, we can do that using <Label>. There is a lot that can be done using forms. You can check out the React documentation on forms for more details. Below is the code for our form:

2   <FormGroup row>
3      <Label for="exampleEmail" sm={2}>Email</Label>
4      <Col sm={10}>
5          <Input type="email" name="email" id="exampleEmail" placeholder="with a placeholder" />
6      </Col>
7   </FormGroup>
9   <FormGroup row>
10      <Label for="examplePassword" sm={2}>Password</Label>
11      <Col sm={10}>
12         <Input type="password" name="password" id="examplePassword" placeholder="password placeholder" />
13      </Col>
14   </FormGroup>
16   <FormGroup row>
17      <Label for="exampleSelect" sm={2}>Select</Label>
18      <Col sm={10}>
19          <Input type="select" name="select" id="exampleSelect" />
20      </Col>
21   </FormGroup>
23   <FormGroup row>
24      <Label for="exampleSelectMulti" sm={2}>Select Multiple</Label>
25      <Col sm={10}>
26        <Input type="select" name="selectMulti" id="exampleSelectMulti" multiple />
27      </Col>
28    </FormGroup>
30  <FormGroup row>
31    <Label for="exampleText" sm={2}>Text Area</Label>
32    <Col sm={10}>
33      <Input type="textarea" name="text" id="exampleText" />
34    </Col>
35  </FormGroup>


The styling and control of list items can be done easily using reactstrap ListGroup. The ListGroupItems are wrapped in ListGroup. The onClick callback can be used to make it interactive. Below is the code for ListGroup;

2  <ListGroupItem>Item 1</ListGroupItem>
3  <ListGroupItem>Item 2</ListGroupItem>
4  <ListGroupItem>...</ListGroupItem>


Buttons can be the most important component for any design framework. There is a reactstrap Button component for buttons. Other than the general active and disabled properties, we can use color and size to set the style (primary, success, etc.) and size (lg, sm, etc.) of buttons:

1{/*ButtonToolbar helps to organize buttons */}
2 <div>
3    <Button color="primary">Primary btn</Button>{' '}
4    <Button color="secondary">Secondary btn</Button>{' '}    
5    <Button color="warning">Warning btn</Button>{' '}
6    <Button color="danger">Danger btn</Button>{' '}
7	<Button color="success">Success btn</Button>{' '}
8    <Button color="info">info btn</Button>{' '}
9    <Button color="link">link btn</Button>
10 </div>


Everything that we need to integrate Bootstrap with React app has been covered in this guide. There are numerous libraries to integrate Bootstrap with React app and we have discussed few of the best known ones. We have also worked with one of the most commonly used libraries, reactstrap.