How to add Bootstrap in React
Today we’ll show you how to add bootstrap in React. There are multiple ways to import bootstrap in react project but we will refer only standard package managers to install bootstrap in ReactJS.
You can also use some other packages such as reactstrap, React Bootstrap, etc.
Steps to add bootstrap in React
1. Create a react application
First, we have to create a simple react application using the create-react-app
npm package. Run the following command to set up a react application.
1 | npx create-react-app add-bootstrap-react |
2. Install bootstrap package
Here, we will use the bootstrap npm package to import bootstrap in react application. Run the following command to install bootstrap.
1 | npm i bootstrap |
After successful installation, you can import CSS or JS in the topmost component of the application. We suggest you import bootstrap CSS at the beginning of your src/index.js
file.
1 | import 'bootstrap/dist/css/bootstrap.min.css'; |
Refer the following link to get more information about this package.
3. Create component using bootstrap
For demonstration, we will use bootstrap in App.js
file to create a simple card. Let’s copy the bootstrap card code from here.
App.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import React from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( <div classname="m-5"> <h5 classname="mb-3">Add Bootstrap in React - <a href="https://cluemediator.com" target="_blank" rel="noopener noreferrer">Clue Mediator</a></h5> <div classname="card" style="{{" width:="" '25rem'="" }}=""> <img src="https://pbs.twimg.com/profile_banners/1187404980988198914/1601635305" classname="card-img-top"> <div classname="card-body"> <h5 classname="card-title">Clue Mediator</h5> <p classname="card-text">Lorem Ipsum is simply a dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.</p> <a href="https://cluemediator.com" target="_blank" classname="btn btn-dark" rel="noopener noreferrer">Visit Website</a> </div> </div> </div> ); } export default App; |
4. Output
Run the application and check the output in the browser.
That’s it for today.
Thank you for reading. Happy Coding..!!