Introduction _ React Bootstrap
Introduction _ React Bootstrap
React Bootstrap
Introduction
Learn how to include React Bootstrap in your project.
Installation
The best way to consume React-Bootstrap is via the npm package which
you can install with npm (or yarn if you prefer).
If you plan on customizing the Bootstrap Sass files, or don't want to use
a CDN for the stylesheet, it may be helpful to install vanilla Bootstrap as
well.
Importing Components
You should import individual components like: react-bootstrap/Button
rather than the entire library. Doing so pulls in only the specific
components that you use, which can significantly reduce the amount of
code you end up sending to the client.
// or less ideally
import { Button } from 'react-bootstrap';
Browser globals
https://react-bootstrap.netlify.app/docs/getting-started/introduction 1/6
1/11/25, 11:23 PM Introduction | React Bootstrap
<script
src="https://cdn.jsdelivr.net/npm/react/umd/react.production.min.
crossorigin></script>
<script
src="https://cdn.jsdelivr.net/npm/react-dom/umd/react-
dom.production.min.js"
crossorigin></script>
<script
src="https://cdn.jsdelivr.net/npm/react-bootstrap@next/dist/rea
bootstrap.min.js"
crossorigin></script>
Examples
React-Bootstrap has started a repo with a few basic CodeSandbox
examples. Click here to check them out.
Stylesheets
Because React-Bootstrap doesn't depend on a very precise version of
Bootstrap, we don't ship with any included CSS. However, some
stylesheet is required to use these components.
CSS
{
/* The following line can be included in your src/index.js
or App.js file */
}
import 'bootstrap/dist/css/bootstrap.min.css';
How and which Bootstrap styles you include is up to you, but the
simplest way is to include the latest styles from the CDN. A little more
https://react-bootstrap.netlify.app/docs/getting-started/introduction 2/6
1/11/25, 11:23 PM Introduction | React Bootstrap
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/boots
integrity="sha384-
QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
Sass
In case you are using Sass the simplest way is to include the Bootstrap’s
source Sass files in your main Sass file and then require it on your
src/index.js or App.js file. This applies to a typical create-react-app
application in other use cases you might have to setup the bundler of
your choice to compile Sass/SCSS stylesheets to CSS.
Customize Bootstrap
If you wish to customize the Bootstrap theme or any Bootstrap variables
you can create a custom Sass file:
https://react-bootstrap.netlify.app/docs/getting-started/introduction 3/6
1/11/25, 11:23 PM Introduction | React Bootstrap
Advanced usage
See the Bootstrap docs for more advanced use cases and details about
customizing stylesheets.
as Prop API
With certain React-Bootstrap components, you may want to modify the
component or HTML tag that is rendered.
RESULT
LIVE EDITOR
RESULT
LIVE EDITOR
function Example() {
return (
<div>
<h1>
Example heading
<Badge bg="secondary" as={Button}>
New
</Badge>
</h1>
</div>
);
}
Themes
React-Bootstrap is compatible with existing Bootstrap themes. Just
follow the installation instructions for your theme of choice.
Watch out!
Because React-Bootstrap completely reimplements Bootstrap's
JavaScript, it's not automatically compatible with themes that
extend the default JavaScript behaviors.
If you would like to add a custom theme on your app using Create
React App, they have additional documentation for Create React
App and Bootstrap here
Browser support
We aim to support all browsers supported by both React and Bootstrap.
https://react-bootstrap.netlify.app/docs/getting-started/introduction 6/6