How to Use Bootstrap with React?
Last Updated :
23 Jul, 2025
Bootstrap is one of the most popular front-end frameworks, widely used to create visually appealing, responsive, and mobile-first websites quickly. It provides pre-designed UI components, grid systems, and various CSS classes that help you build mobile-first, responsive web applications quickly and efficiently.
In this article, we’ll walk you through how to use Bootstrap with React effectively.
How to Use Bootstrap with React?
Bootstrap with React
To use Bootstrap in React and style using the Bootstrap classes we can directly add the Bootstrap CDN in html file, use the Bootstrap npm package and also use the React-Bootstrap library which directly provides the styled React Components.
There are mainly three main ways to use Bootstrap with the ReactJS app.
Three Ways to Use Bootstrap with React
- Using the Bootstrap CDN
- Importing Bootstrap as a Dependency
- Using React-Bootstrap
Method 1: Using the Bootstrap CDN
Step 1. Add the Bootstrap CSS link
In your public/index.html file, add the following line inside the <head> section to include the Bootstrap CSS:
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/5.3.2/css/bootstrap.min.css"
crossorigin="anonymous"
/>
Step 2. Add Bootstrap’s JavaScript files
If your app requires Bootstrap’s interactive JavaScript components (like modals, tooltips, etc.), add the following scripts just before the closing </body> tag:
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/5.3.2/js/bootstrap.min.js"
crossorigin="anonymous"
></script>
Here is the implementation
HTML
<!-- Filename - public/index.html -->
<html lang="en">
<head>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-d4E8z2JwGe7y5ZK0K4dU2kjT7v43QzxB2+pN8ARdI9lDlZORFfop9tFfjG4PUwsw"
crossorigin="anonymous">
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-oBqDVmMz4fnFO9gyb56E8fR+6xKnujsH1X2jxXUSqWExY0g0U7tUdbzPvV4H8nX"
crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-pzjw8f+ua7Kw1TIq0sStbd5Y7fuD9BqR6O3doBoq3UMaS2m5uZlZKHw3LFG2Orv6"
crossorigin="anonymous">
</script>
</body>
</html>
Output
Using the Bootstrap CDN In this code
- Includes the Bootstrap 5.3.2 CSS via CDN for styling the application.
- Loads Popper.js and Bootstrap's JavaScript bundle (which includes necessary plugins) at the end of the <body>.
- Contains a <div id="root"></div> as the mounting point for the React app.
Method 2: Import Bootstrap as a Dependency
If we prefer managing your app's dependencies, you can install Bootstrap through npm and import it into your React app. This method is especially useful when working with module bundlers like Webpack or when you want more control over the package versions.
Steps to Install and Import Bootstrap
1. Install Bootstrap and Supporting Libraries
Run the following command to install Bootstrap and Popper.js (which are required for certain Bootstrap components) as dependencies:
npm install bootstrap @popperjs/core
2. Import Bootstrap in Your React App
After installing the packages, open your src/index.js (or src/index.tsx for TypeScript) and import Bootstrap CSS:
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min';
Here is the implementation :
JavaScript
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap/dist/js/bootstrap.bundle.min";
import React from "react";
import "./App.css";
function App() {
return (
<div className="App">
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<a className="navbar-brand" href="#">
Navbar
</a>
<button
className="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarNav"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNav">
<ul className="navbar-nav">
<li className="nav-item active">
<a className="nav-link" href="#">
Home <span className="sr-only">(current)</span>
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Features
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Pricing
</a>
</li>
</ul>
</div>
</nav>
<div className="container mt-5">
<div className="row">
<div className="col-md-6">
<div className="card">
<div className="card-body">
<h5 className="card-title">Card title</h5>
<p className="card-text">
Some quick example text to build on the card title and make up
the bulk of the card's content.
</p>
<a href="#" className="btn btn-primary">
Go somewhere
</a>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
export default App;
Output
Import Bootstrap as a DependencyIn this code
- This App.js sets up a simple layout with Bootstrap.
- It includes a responsive navbar that collapses on smaller screens, a card component with a title, text, and a button. Bootstrap's JavaScript features are enabled by importing jQuery, Popper.js, and Bootstrap's bundle.
- The page also uses Bootstrap's grid system for layout and spacing.
Method 3: Using React-Bootstrap
For a more React-friendly approach, you can use the React-Bootstrap library, which provides pre-built Bootstrap components as React components. React-Bootstrap helps to seamlessly integrate Bootstrap’s UI elements into your React applications without relying on jQuery.
Steps to Use React-Bootstrap
1. Install React-Bootstrap and Bootstrap
Run the following command to install both the react-bootstrap package and Bootstrap itself:
npm install react-bootstrap bootstrap
2. Import React-Bootstrap Components
React-Bootstrap allows you to use Bootstrap components as React components. For example, to add a navbar and a button:
JavaScript
import React from 'react';
import { Navbar, Nav, Button } from 'react-bootstrap';
function App() {
return (
<div>
<Navbar bg="dark" variant="dark" expand="lg">
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Nav className="me-auto"> {/* Updated from 'mr-auto' to 'me-auto' */}
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
</Nav>
</Navbar>
<Button variant="primary">Click Me!</Button>
</div>
);
}
export default App;
Output
Using React-BootstrapIn this code
- This App.js renders a simple React-Bootstrap layout with a dark-themed navbar, three responsive cards in a grid, and a footer.
- Each card includes an image, title, description, and a button with different variants.
- The layout is responsive, adjusting the number of cards per row based on screen size.
- The footer is styled with a dark background and centered text.
Project Setup for React-Bootstrap
- Create a React App: If you haven't already, create a new React app using the following command:
npx create-react-app my-app
cd my-app
- Install Dependencies: Install axios, bootstrap, and reactstrap:
npm install axios bootstrap react-bootstrap
- Project Structure : The Project Structure will look like this.

Dependency list After installing packages
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"axios": "^1.6.0",
"bootstrap": "^5.3.2",
"react": "^18.3.0",
"react-bootstrap": "^2.11.0",
"react-dom": "^18.3.0",
"react-router-dom": "^6.18.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
- Implementation : Here's a simple implementation of a web page using react-bootstrap with navbar, dropdown, cards and and posts.
JavaScript
// Filename - App.js
import React, { Fragment } from "react";
import "bootstrap/dist/css/bootstrap.min.css";
import axios from "axios";
import { Container, Row, Col } from "react-bootstrap";
import Post from "./components/Post";
import Header from "./components/Header";
import LeftCard from "./components/LeftCard";
const App = () => (
<Fragment>
<Header />
<main className="my-5 py-5">
<Container className="px-0">
<Row
className="pt-2 pt-md-5 w-100 px-4 px-xl-0 position-relative g-0"
>
<Col
xs={{ order: 2 }}
md={{ span: 4, order: 1 }} // Updated `size` to `span` in Bootstrap 5
tag="aside"
className="pb-5 mb-5 pb-md-0 mb-md-0 mx-auto mx-md-0"
>
<LeftCard />
</Col>
<Col
xs={{ order: 1 }}
md={{ span: 7, offset: 1 }} // Updated `size` to `span` in Bootstrap 5
tag="section"
className="py-5 mb-5 py-md-0 mb-md-0"
>
<Post />
</Col>
</Row>
</Container>
</main>
</Fragment>
);
export default App;
Output: This output will be visible on http://localhost:3000/ on the browser window.
In this code
- This App.js creates a responsive layout with Bootstrap.
- It displays a header and two columns: one for a left-side card (LeftCard) and another for main content (Post).
- The layout adjusts based on screen size using Bootstrap's grid system (Col, Row).
- The Fragment is used to return multiple components without extra DOM nodes.
How to Customize Bootstrap in React?
Bootstrap is an excellent front-end framework that provides ready-to-use components for building responsive websites. However, in many cases, you may want to customize these components to fit the style of your React app. In this section, we'll explain how to customize Bootstrap in React with a simple example
Step 1: Install Bootstrap in Your React Project
To get started, you need to install Bootstrap in your React project. You can do this by running the following command:
npm install bootstrap
Step 2: Import Bootstrap CSS
Once Bootstrap is installed, you can import its CSS into your React app. Go to your src/index.js (or src/index.tsx for TypeScript) file and add the following import statement at the top:
import 'bootstrap/dist/css/bootstrap.min.css';
Step 3: Create a Custom CSS File for Your Customizations
The easiest way to customize Bootstrap in React is by overriding its default styles with your own custom CSS. You can create a new CSS file, such as src/custom.css, to add these overrides.
/* custom.css */
/* Change the background color of the primary button */
.btn-primary {
background-color: #4CAF50; /* Green color */
border-color: #4CAF50;
}
/* Change the navbar background to dark */
.navbar {
background-color: #333; /* Dark background for navbar */
}
Step 4: Import the Custom CSS File
After creating the custom styles, you need to import the custom.css file into your app. Go back to src/index.js and add this import statement after the Bootstrap CSS import:
import './custom.css'; // Import your custom styles
Step 5: Use Bootstrap Components with Your Custom Styles
Now that you've added custom styles, you can start using Bootstrap components in your React app. Here's a simple example that includes a Navbar and a Primary Button with the custom styles applied:
CSS
/* custom.css */
.btn-primary {
background-color: #4CAF50;
border-color: #4CAF50;
}
.navbar {
background-color: #333;
}
JavaScript
import React from "react";
import { Button, Navbar, Nav } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import "./custom.css";
function App() {
return (
<div>
<Navbar bg="light" expand="lg">
<Navbar.Brand href="#home">Custom Bootstrap</Navbar.Brand>
<Nav className="me-auto"> {/* Updated from 'mr-auto' to 'me-auto' */}
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
</Nav>
</Navbar>
<div className="container mt-4">
<Button variant="primary">Click Me!</Button>
</div>
</div>
);
}
export default App;
Output
Customize BootstrapIn this code
- Navbar Customization: The navbar has a default Bootstrap background, but we’ve customized it to have a dark color (#333) using our custom CSS.
- Button Customization: The primary button uses the .btn-primary class from Bootstrap. We’ve overridden its default blue background to a green (#4CAF50), also using our custom CSS.
Conclusion
In this article, we covered three methods for using Bootstrap in a React app: using the Bootstrap CDN for quick setup without installation, importing Bootstrap as a dependency for npm-based package management, and React-Bootstrap for a more React-friendly approach with Bootstrap components as React components. Each method offers unique advantages based on your project needs.
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.What are Reactjs Functio
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