How to replace container class in react-bootstrap?
Last Updated :
28 Apr, 2025
The container class provides a responsive fixed-width container. In this article, we will learn How to replace container class in react-bootstrap. We will wrap the outermost content so that the page has margins.
Steps to create React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. folder name, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install react-bootstrap --save
npm install --save bootstrap@latest
Step 4: Import the CSS by
import 'bootstrap/dist/css/bootstrap.css';
Project Structure:

The updated dependencies in package.json file will look like
Approach 1: Using React Bootstrap Container
Using React Bootstrap Container: In this approach, we will use Container class from react-bootstrap/Container. we will create a Navbar within a container
JavaScript
import Container from 'react-bootstrap/Container';
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import NavDropdown from 'react-bootstrap/NavDropdown';
export default function App() {
return (
<div>
<h2 style={{color:'green'}}>GeeksforGeeks</h2>
<h2>
How to replace container class in react-bootstrap?
</h2>
<Navbar expand="lg" bg="warning" >
<Container>
<Navbar.Brand href="#home">GeeksforGeeks</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="me-auto">
<Nav.Link href="#home">Java</Nav.Link>
<Nav.Link href="#c++">C++</Nav.Link>
<Nav.Link href="#android">Android</Nav.Link>
<Nav.Link href="#spring">Springboot</Nav.Link>
<Nav.Link href="#python">Python</Nav.Link>
<NavDropdown title="Web Technology" id="collasible-nav-dropdown">
<NavDropdown.Item href="#web/3.1">React</NavDropdown.Item>
<NavDropdown.Item href="#web/3.2">
Angular
</NavDropdown.Item>
<NavDropdown.Item href="#web/3.3">HTML</NavDropdown.Item>
<NavDropdown.Item href="#web/3.3">CSS</NavDropdown.Item>
<NavDropdown.Item href="#web/3.3">Javascript</NavDropdown.Item>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
</div>
);
}
Output:

Approach 2: Using Traditional Bootstrap
Using Traditional bootstrap: In this approach we will add a container class by importing bootstrap from 'import 'bootstrap/dist/css/bootstrap.css'
JavaScript
import 'bootstrap/dist/css/bootstrap.css';
export default function App() {
return (
<div>
<h2 style={{color:'green'}}>GeeksforGeeks</h2>
<h2>
How to replace container class in react-bootstrap?
</h2>
<div className="container" style={{background:'green',color:'white'}}>
I am in Traditional container
</div>
</div>
);
}
Output:

.
Similar Reads
How to Add a classname/id to React-Bootstrap Component ? In this article, we will learn how we can add a class name and ID to a React-Bootstrap component. ClassName and ID can be used to target elements while styling and scripting (which means writing logic) the application.Prerequisites:React JSReact-BootstrapSteps to create React app and install bootstr
4 min read
How to Customize the grid layout in React Bootstrap? In this article, we will be customizing the grid layout in React Bootstrap. Grid layout is used to align the elements with ting the grid format according to the requirements. In React Bootstrap, we can control the number of columns, spacing, responsiveness, and other properties to create a more attr
5 min read
How to create your own React Bootstrap theme ? In this article, we will learn how to create our own react-bootstrap theme on a website Themestr.app and add it to our react project.Features:No need to think about responsiveness.A wide range of color options is available to choose from.Very easy to work and integrate into the project.Prerequisite:
3 min read
How to Add a Border to a Container in Bootstrap ? Borders in Bootstrap are a styling element used to enhance the visual appearance of containers, buttons, and other elements. They can be customized with various colors, thicknesses, and styles to create distinct visual effects. Below are the approaches to add a border to a container in Bootstrap: Ta
3 min read
How to Create Dark/Light Theme in Bootstrap with React? Creating dark/light themes and integrating them into a React application enhances user experience by providing visual customization options, improving readability, and allowing users to switch between themes based on their preferences. In this article, we will learn to create dark/light theme in Boo
3 min read