Bootstrap with React
Learn how to install Bootstrap and use its ready-made utility classes directly inside React components, plus a look at react-bootstrap.
Introduction
Writing every single style rule by hand is not always the best use of your time, especially for common UI patterns like buttons, cards, and grids that have been solved thousands of times already. Bootstrap is one of the most popular CSS frameworks for exactly this reason — it ships a huge set of ready-made classes you can apply directly to your markup.
Because Bootstrap is just CSS (plus some optional JavaScript for things like modals), it works in React with almost no special setup: you install the package, import its stylesheet once, and then use its class names in your JSX exactly like you would in the className attribute of any element. This lesson walks through that setup, shows practical examples, and introduces react-bootstrap, a companion library that wraps Bootstrap's markup and behavior in ready-made React components.
- How to install Bootstrap with npm and import its CSS globally.
- How to apply Bootstrap's utility and component classes directly in JSX.
- How to build a simple card and button using only className.
- What react-bootstrap is and how it differs from plain Bootstrap classes.
Installing Bootstrap
Bootstrap is distributed as an npm package, just like any other JavaScript dependency. Install it into your React project with npm.
npm install bootstrapOnce installed, import Bootstrap's compiled CSS file once, typically at the top level of your app — in main.jsx, index.js, or App.jsx — so its styles apply globally across every component.
import 'bootstrap/dist/css/bootstrap.min.css';
import { createRoot } from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')).render(<App />);You only need to import bootstrap/dist/css/bootstrap.min.css once in your entire app, at the root entry file. Every component can then use Bootstrap's classes without importing anything else.
Using Bootstrap Classes in JSX
Once the stylesheet is loaded, Bootstrap's classes behave exactly like any other CSS class — you apply them through the className attribute in JSX (remember, className instead of HTML's class).
Layout Utilities
Classes like container, row, and col-md-6 build responsive grid layouts.
Spacing Utilities
Classes like p-3, mt-4, and mx-auto control padding and margin without custom CSS.
Component Classes
Classes like btn, btn-primary, and card style common UI patterns instantly.
Responsive Helpers
Classes like d-none and d-md-block show or hide content at different screen sizes.
Example: A Bootstrap Card
Here is a simple profile card built entirely with Bootstrap's card component classes and spacing utilities — no custom CSS file needed at all.
function ProfileCard() {
return (
<div className="card" style={{ width: '18rem' }}>
<div className="card-body">
<h5 className="card-title">Amol Chipte</h5>
<h6 className="card-subtitle mb-2 text-muted">Frontend Developer</h6>
<p className="card-text">Builds fast, accessible interfaces with React.</p>
<a href="#" className="btn btn-primary">View Profile</a>
</div>
</div>
);
}
export default ProfileCard;A bordered card with a title, subtitle, description paragraph, and a blue "View Profile" button.Example: A Bootstrap Button
Bootstrap ships several ready-made button variants. Combining btn with a variant class like btn-success gives you a fully styled, accessible button with zero custom CSS.
function SubmitButton({ onClick }) {
return (
<button type="button" className="btn btn-success px-4 py-2" onClick={onClick}>
Submit
</button>
);
}
export default SubmitButton;A green, rounded "Submit" button with comfortable horizontal and vertical padding.react-bootstrap: Component Wrappers
Using className strings works well, but it means you are still writing markup structure by hand and remembering exact class name combinations. react-bootstrap is a separate library that wraps Bootstrap's components and behavior into actual React components, like <Button> and <Card>, so you write JSX instead of memorizing class names.
npm install react-bootstrap bootstrapimport Button from 'react-bootstrap/Button';
import Card from 'react-bootstrap/Card';
function ProfileCard() {
return (
<Card style={{ width: '18rem' }}>
<Card.Body>
<Card.Title>Amol Chipte</Card.Title>
<Card.Text>Builds fast, accessible interfaces with React.</Card.Text>
<Button variant="primary">View Profile</Button>
</Card.Body>
</Card>
);
}react-bootstrap still relies on Bootstrap's CSS under the hood — it just replaces the plain className markup with prebuilt React components and props, which can make interactive elements like modals and dropdowns easier to wire up.
Plain Bootstrap vs react-bootstrap
Both approaches load the same underlying Bootstrap styles, so the choice mostly comes down to how much you want React managing the markup and behavior for you.
| Aspect | Plain Bootstrap classes | react-bootstrap |
|---|---|---|
| Setup | Install bootstrap, import CSS once | Install both react-bootstrap and bootstrap |
| Usage | Add className strings to elements | Import and use JSX components like <Button> |
| Interactive widgets (modals, dropdowns) | Requires Bootstrap's JS bundle plus manual wiring | Handled internally as React state and props |
| Learning curve | Just class names | An additional component API to learn |
| Bundle size | Only CSS (plus optional JS) | Adds the react-bootstrap package on top |
Common Mistakes
- Forgetting to import bootstrap/dist/css/bootstrap.min.css, so none of the utility classes apply even though the package is installed.
- Writing class instead of className, which React (and JSX) does not recognize as the attribute for setting CSS classes.
- Mixing plain Bootstrap classes and react-bootstrap components inconsistently across a project without a clear reason.
- Assuming interactive Bootstrap widgets like modals and dropdowns work with just the CSS file — some depend on Bootstrap's own JavaScript, which react-bootstrap replaces with its own implementation.
Best Practices
- Import Bootstrap's CSS exactly once, at your app's entry point.
- Use plain Bootstrap classes for simple, static layouts and quick prototyping.
- Reach for react-bootstrap when you need interactive components like modals, dropdowns, or tooltips with React-managed state.
- Avoid mixing large amounts of custom CSS with Bootstrap unless you understand how the cascade and specificity will interact.
- Check the official Bootstrap and react-bootstrap documentation for the exact class names and component props you need.
Frequently Asked Questions
Do I need react-bootstrap to use Bootstrap in React?
No. Plain Bootstrap classes work perfectly well applied directly through className. react-bootstrap is an optional convenience layer, not a requirement.
Will Bootstrap classes conflict with my own CSS Modules?
They can, since Bootstrap classes are global. Be mindful of specificity and naming when combining Bootstrap classes with your own scoped or global styles.
Can I customize Bootstrap's default colors and spacing?
Yes, through Bootstrap's Sass variables if you install the Sass source instead of the precompiled CSS, though that setup is more advanced than importing the plain CSS file.
Is Tailwind CSS better than Bootstrap for React?
Neither is objectively better — they take different approaches. Bootstrap provides prebuilt components and utilities, while Tailwind is more utility-first and typically requires more manual composition. The right choice depends on your project.
Does react-bootstrap require Bootstrap's own JavaScript file?
No. react-bootstrap reimplements Bootstrap's interactive behavior using React itself, so you do not need to include Bootstrap's bundled JavaScript separately.
Key Takeaways
- Bootstrap installs with npm install bootstrap and its CSS is imported once at the app's entry point.
- Bootstrap's utility and component classes apply directly through the className attribute in JSX.
- A card, button, or layout can be built entirely with Bootstrap classes and no custom CSS.
- react-bootstrap wraps Bootstrap's markup and behavior into reusable React components like <Button> and <Card>.
- Plain classes and react-bootstrap both use the same underlying styles, differing mainly in how much structure React manages for you.
Summary
Bootstrap gives you a large, battle-tested set of CSS classes you can apply directly in JSX with almost no setup, making it a fast way to build clean, consistent interfaces without writing custom CSS. react-bootstrap takes this further by wrapping the same styles into ready-made React components for more complex, interactive widgets.
This wraps up the styling section of the course. Next, you will move on to React Fragments, a small but handy feature for returning multiple elements from a component without adding an extra wrapper node to the DOM.
- You can install Bootstrap and import its CSS into a React app.
- You can apply Bootstrap's utility and component classes directly in JSX.
- You built a card and a button using only className.
- You understand how react-bootstrap differs from plain Bootstrap classes.
- You are ready to learn about React Fragments.