Introduction

In this blog, you will learn to install bootstrap in your React application. We will see how to use bootstrap in React.

What is bootstrap?

Bootstrap is a free front-end framework for faster and easier web development; Bootstrap includes HTML and CSS-based design templates.
Step 1
Create a brand new react application or open an existing one. Open the terminal in Visual Studio Code or in the command prompt and follow the below steps.
  1. E:\REACT PROJECTS>npx create-react-app counter-app
  2. E:\REACT PROJECTS>cd counter-app
  3. E:\REACT PROJECTS>npm install bootstrap –save
  4. E:\REACT PROJECTS\counter-app>code .
If you are in Visual Studio terminal, follow the below steps:
  1. PS E:\REACT PROJECTS\counter-app>
  2. npm install bootstrap –save
Step 2
Now register your bootstrap and font-awesome in Index.js which is located under the src folder of your application.
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import "./index.css";
  4. import App from "./App";
  5. import * as serviceWorker from "./serviceWorker";
  6. import bootstrap from "bootstrap/dist/css/bootstrap.min.css";
  7. ReactDOM.render(
  8. <React.StrictMode>
  9. <App />
  10. </React.StrictMode>,
  11. document.getElementById("root")
  12. );
  13. serviceWorker.unregister();
Step 3
Open App.js and modify it as shown below.
  1. import React from "react";
  2. import logo from "./logo.svg";
  3. import "./App.css";
  4. function App() {
  5. return (
  6. <div className="container py-4">
  7. <h1 className="text-center text-uppercase">
  8. Welcome to react app development
  9. </h1>
  10. <div>
  11. <h3>Bootstrap 4 Buttons</h3>
  12. <button type="button" className="btn btn-primary rounded-0">
  13. Primary
  14. </button>
  15. <button type="button" className="btn btn-secondary rounded-0">
  16. Secondary
  17. </button>
  18. <button type="button" className="btn btn-light rounded-0">
  19. Light
  20. </button>
  21. <button type="button" className="btn btn-danger rounded-0">
  22. Danger
  23. </button>
  24. <button type="button" className="btn btn-success rounded-0">
  25. Success
  26. </button>
  27. <button type="button" className="btn btn-info rounded-0">
  28. info
  29. </button>
  30. <button type="button" className="btn btn-warning rounded-0">
  31. Warning
  32. </button>
  33. <button type="button" className="btn btn-dark rounded-0">
  34. Dark
  35. </button>
  36. </div>
  37. </div>
  38. );
  39. }
  40. export default App;