AskHandle

AskHandle Blog

Utilizing React with Bootstrap for Modern Web Development

May 27, 2025Alicia Gopin3 min read

Utilizing React with Bootstrap for Modern Web Development

Building modern web applications often involves choosing the right set of tools and libraries to achieve a seamless, responsive, and efficient user experience. Two tools that stand out in the web development landscape are React and Bootstrap.

React, a JavaScript library for building user interfaces, is developed and maintained by Facebook, and it helps in creating fast, scalable, and simple applications. Bootstrap, originally developed by Twitter, is a front-end framework designed to make developing responsive, mobile-first sites a breeze. Combining React with Bootstrap offers a powerful toolkit for developers.

Setting Up React with Bootstrap

To begin integrating Bootstrap with a React project, you need a basic React application. You can create one using Create React App. If you haven't already, install Create React App globally using npm:

bash
1npm install -g create-react-app

Then, create a new React application:

bash
1create-react-app react-bootstrap-app
2cd react-bootstrap-app

Next, you need to install Bootstrap. Using the npm package manager, you can easily add Bootstrap to your project:

bash
1npm install bootstrap

Now, you need to include Bootstrap in your project. Open the src/index.js file and import Bootstrap's CSS:

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

With Bootstrap integrated, you can start using its components to style your React application.

Building Components with Bootstrap

Bootstrap provides many pre-built components that you can use in your React application. Let's create a simple layout using Bootstrap's grid system and a Navbar component.

First, let's create a Navbar component.

Create a new file src/components/Navbar.js:

javascript
1import React from 'react';
2import 'bootstrap/dist/css/bootstrap.min.css';
3import { Navbar, Nav, NavDropdown } from 'react-bootstrap';
4
5const AppNavbar = () => {
6  return (
7    <Navbar bg="dark" variant="dark" expand="lg">
8      <Navbar.Brand href="#">React-Bootstrap</Navbar.Brand>
9      <Navbar.Toggle aria-controls="basic-navbar-nav" />
10      <Navbar.Collapse id="basic-navbar-nav">
11        <Nav className="mr-auto">
12          <Nav.Link href="#home">Home</Nav.Link>
13          <Nav.Link href="#link">Link</Nav.Link>
14          <NavDropdown title="Dropdown" id="basic-nav-dropdown">
15            <NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
16            <NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
17            <NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
18            <NavDropdown.Divider />
19            <NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
20          </NavDropdown>
21        </Nav>
22      </Navbar.Collapse>
23    </Navbar>
24  );
25};
26
27export default AppNavbar;

This component uses react-bootstrap to render a responsive navigation bar. Notice the use of Bootstrap's classes to style the navigation.

Using the Navbar Component

Open the src/App.js file and include the Navbar component:

javascript
1import React from 'react';
2import './App.css';
3import AppNavbar from './components/Navbar';
4
5function App() {
6  return (
7    <div className="App">
8      <AppNavbar />
9      <header className="App-header">
10        <h1>Welcome to React with Bootstrap</h1>
11        <p>Explore the power of combining these two libraries.</p>
12      </header>
13    </div>
14  );
15}
16
17export default App;

Your React application now has a responsive Bootstrap-styled navigation bar.

Creating the Main Layout with the Grid System

Bootstrap's grid system allows you to set up responsive layouts with ease. Let's create a main layout with a sidebar and a content area.

Create a new file called MainLayout.js in the src/components directory:

javascript
1import React from 'react';
2import { Container, Row, Col } from 'react-bootstrap';
3
4const MainLayout = () => {
5  return (
6    <Container fluid>
7      <Row>
8        <Col sm={3} className="bg-light">
9          <h2>Sidebar</h2>
10          <ul>
11            <li>Link 1</li>
12            <li>Link 2</li>
13            <li>Link 3</li>
14          </ul>
15        </Col>
16        <Col sm={9} className="bg-white">
17          <h2>Main Content</h2>
18          <p>This is the main content area.</p>
19        </Col>
20      </Row>
21    </Container>
22  );
23};
24
25export default MainLayout;

This component uses Bootstrap's grid system with two columns. One column serves as a sidebar, and the other as the main content area.

Using the Layout Component

Now, integrate your newly created layout component into the App.js:

javascript
1import React from 'react';
2import './App.css';
3import AppNavbar from './components/Navbar';
4import MainLayout from './components/MainLayout';
5
6function App() {
7  return (
8    <div className="App">
9      <AppNavbar />
10      <MainLayout />
11    </div>
12  );
13}
14
15export default App;

Styling with Bootstrap and Custom CSS

Bootstrap provides a robust foundation for styling, but sometimes custom styles are necessary. You can add custom styling in a CSS file, and the classes can be combined with Bootstrap's classes.

Create a new file called App.css in the src directory:

css
1.App-header {
2  background-color: #282c34;
3  padding: 20px;
4  color: white;
5}
6
7.bg-light {
8  background-color: #f8f9fa !important;
9}
10
11.bg-white {
12  background-color: #ffffff !important;
13}

These styles can be used alongside Bootstrap's styles to fine-tune your application's appearance.

Benefits of Using React with Bootstrap

  1. Development Speed: Simplifies layout creation and styling, resulting in a faster development process.
  2. Consistency: Ensures a consistent look and feel across the application by using Bootstrap's design elements.
  3. Responsive Design: Automatically provides a responsive layout to accommodate various screen sizes.
  4. Reusable Components: Leverages React's component-based architecture with Bootstrap's pre-built components for modular and reusable code.

Resources

For further reading and exploration, consider the following resources:

Combining React with Bootstrap can significantly streamline your web development process, providing a robust foundation for building modern, responsive web applications. Start integrating these powerful tools into your projects and experience the benefits firsthand!