How to use Bootstrap in React Using a React Library
Tags: webdev, react, codenewbie, html
Published: 2021-04-22 22:03:41

---
title: How to use Bootstrap in React Using a React Library
published: true
date: 2015-05-06 23:46:37 UTC
tags: [webdev, react, codenewbie, html]
canonical_url: https://www.devwares.com/blog//using-bootstrap-in-react
---

React is one of the most popular javascript frontend frameworks out there and its popularity does not come as a surprise as it is very flexible to use. Bootstrap on the other hand is an open-source CSS framework that features many templates for user interface components such as cards and modals.


![AD-BANNER](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41meil9ho9yx2ulb535m.png)

In this article, we will be making use of these two frameworks alongside a react library to create a simple landing page. The library we’ll be making use of is CDBReact which is an Elegant UI kit that has reusable components for building mobile-first, responsive websites, and web apps.

**Prerequisites**

  
The Landing page would be built with React, Bootstrap, and CDBReact. You don’t need to have any previous knowledge of CDBReact. Basic React Knowledge Basic Bootstrap knowledge NPM installed

This is an image of the Landing page that we will build.

  

![Bootstrap Landing Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msdafgchigfqv4x0ga71.png)

  

**Setup**

First Check that you have node installed. To do this, run the following code

```javascript
node -v

```

If you don’t have nodejs installed, download it [here](https://nodejs.org/en/)

Installing node also installs npm on your PC but you can still confirm using

```javascript
npm -v.

```

Now that we have node installed, we can start up our React project by going to the directory of our choice and running

```javascript
npx create-react-app landing-page

```

I chose landing-page for the name of my project but you can use whatever you want.

  

**Install cdbreact**

Now, we have to install cdbreact in our project

```javascript
npm install --save cdbreact

```

Or using Yarn

```javascript
yarn add cdbreact

```

Note that we dont need to install bootstrap or add it anywhere in our project as CDBReact does that for us upon installation.

Also Install React router because it is required by the Navbar we’ll be creating.

```javascript
npm install react-router-dom

```

Now run `npm start` to make sure that everything runs smoothly

### Navbar

Now let’s proceed to create a navbar for our landing page.

Create a file named Navbar

Import Navbar and other components we will be using from cdbreact

```javascript
import React, { useState } from 'react';

import {

  CDBBtn,

  CDBNavbar,

  CDBNavBrand,

  CDBNavbarNav,

  CDBNavToggle,

  CDBNavItem,

  CDBNavLink,

  CDBCollapse,

} from 'cdbreact';

```

After that, add the following code for the navbar.

```javascript
const Navbar = () => {

  const [collapse, setCollapse] = useState(false);

  return (

    <header

      className="page-header"

      style={{ width: '60%', margin: '0 auto', 'max-width': '1320px' }}

    >

      <CDBNavbar

        className="navigation bg-transparent p-0"

        expand="md"

        dark

        scrolling

      >

        <CDBNavBrand href="/">

          <img alt="logo" src="/logo192.png" width="25px" />

        </CDBNavBrand>

        <CDBNavToggle

          onClick={() => {

            setCollapse(!collapse);

          }}

        />

        <CDBCollapse id="navbarCollapse1" delay="0" isOpen={collapse} navbar>

          <CDBNavbarNav>

            <CDBNavItem active>

              <CDBBtn flat className="p-2 border-0 bg-transparent">

                <CDBNavLink to="#">Home</CDBNavLink>

              </CDBBtn>

            </CDBNavItem>

            <CDBNavItem>

              <CDBBtn flat className="p-2 border-0 bg-transparent">

                <CDBNavLink to="#">Resources</CDBNavLink>

              </CDBBtn>

            </CDBNavItem>

            <CDBNavItem>

              <CDBBtn flat className="p-2 border-0 bg-transparent">

                <CDBNavLink to="#">Blog</CDBNavLink>

              </CDBBtn>

            </CDBNavItem>

            <CDBNavItem>

              <CDBBtn flat className="p-2 border-0 bg-transparent">

                <CDBNavLink to="#">Contact</CDBNavLink>

              </CDBBtn>

            </CDBNavItem>

            <CDBNavItem>

              <CDBBtn flat className="p-2 border-0 bg-transparent">

                <CDBNavLink to="#">Support</CDBNavLink>

              </CDBBtn>

            </CDBNavItem>

          </CDBNavbarNav>

        </CDBCollapse>

      </CDBNavbar>

    </header>

  );

};

export default Navbar;

```

From the piece of code above,we imported the necessary components from cdbreact and then we also created a collapse state that will be used by the navbar to know when it is open or not. We can notice some bootstrap clases such as ‘p-2’ and ‘border-0’ being used in the styling of the navbar.

  

Let’s import the Navbar into our App.js and also include our router from react-router-dom.

```javascript
import './App.css';

import Navbar from './Navbar';

import { BrowserRouter as Router } from 'react-router-dom';

function App() {

  return (
    <Router>

      <div className="App">

        <Navbar />

      </div>

    </Router>

  );

}

export default App;

```

Now lets edit our App.css file to give our page a black background colour

```javascript
.App {
  background-color: black;
}

```

After this, your navbar should appeared like in the image below.

  
![Bootstrap Landing Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msdafgchigfqv4x0ga71.png)

Now lets move on to creating the rest of the page.

### Landing Component

Create a new file called landing.js and in it, create a component called landing, also create a landing.css file that would be used for styling.

In your Landing.js, addd the following code

```javascript
import React from 'react';

import './landing.css';

import { CDBBtn } from 'cdbreact';

const Landing = () => {

  return (

    <section className="page-head d-flex align-items-center text-right text-white">

      <img alt="landing" src="/landing.png" className="image" />

      <div className="page-info">

        <p className="page-title font-weight-bold ml-auto">

          Creativity is but skin deep

        </p>

        <p className="my-4">

          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit, error

          amet numquam iure provident voluptate esse quasi, veritatis totam

          voluptas nostrum quisquam eum porro a pariatur accusamus veniam.

        </p>

        <CDBBtn

          flat

          style={{ background: '#8080ff', border: '2px #8080ff solid' }}

        >

          Start Now

        </CDBBtn>

      </div>

    </section>

  );

};

export default Landing;

```

Here we import the landing.css file, we also import CDBBtn component from CDBReact and then use a number of bootstrap classes such as d-flex, align-items-center, and my-4 for styling. Also notice that we can pass custom styles to CDBReact components like we did to CDBBtn above.

Also add the following to your landing.css file.

```css
.page-head {
  margin: 5rem auto 0 auto;
  width: 80%;
}

.page-head .image {
  width: 50%;
  max-width: 550px;
}

.page-info {
  width: 50%;
  text-align: right;
}

.page-title {
  font-size: 3em;
  max-width: 350px;
}

.page-info .btn {
  max-width: 200px;
}

```

Then import the landing component into your App.js file, to make it look like this:

```javascript

import './App.css';

import Navbar from './Navbar';

import { BrowserRouter as Router } from 'react-router-dom';

import Landing from './landing';

function App() {

  return (

    <Router>
      <div className="App">
        <Navbar />
        <Landing />
      </div>
    </Router>

  );

}

export default App;

```

Now your landing page should be ready and look like the image below.


![Bootstrap Landing Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msdafgchigfqv4x0ga71.png)

Congratulations, you have successfully built a landing page using react, bootstrap and CDBReact. Easy isn’t it? Pairing these tools can help you create awesome webpages that look beautiful in no time.

**Resources**

[CDBReact docs](https://www.devwares.com/docs/contrast/react/index)

[Bootstrap docs](https://getbootstrap.com/docs/4.0/getting-started/introduction/)

[Link to code on github](https://github.com/Chimdiya1/article-landing-page)


###Create Stunning Websites and Web Apps

Building different custom components in react for your web apps or websites can get very stressful. That's why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro. [Try contrast pro!](https://www.devwares.com/product/contrast-pro)

![Contrast Design Boostrap](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ulsutxnzjpbpaauhvbew.png)

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc project with a clean, well documented, well crafted template and UI components. [Learn more about Contrast Pro](https://www.devwares.com/product/contrast-pro)

## Resources 

- [Get Contrast PRO](https://www.devwares.com/product/bootstrap-contrast-pro)

- [How to use tailwind css in HTML]  (https://www.devwares.com/blog/how-to-use-tailwind-css-in-HTML)

- [Why tailwind CSS is good](https://www.devwares.com/blog/why-tailwind-css-is-good)

- [How to use Tailwind CSS in Nextjs](https://www.devwares.com/blog/tailwind-css-in-nextjs)

- [How to create Tailwind CSS Components for your Website](https://www.devwares.com/blog/how-to-create-tailwind-css-components-for-your-website)

- [How to create Tailwind CSS Animation](https://www.devwares.com/blog/create-animation-with-tailwind-css/)

- [Tailwind grid-How to use tailwind CSS grid templates in your project](https://www.devwares.com/blog/how-to-add-tailwind-css-grid-to-your-project/)

- [How to create a Beautiful Responsive Navigation bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-create-a-beautiful-responsive-navbar-using-tailwind-css/)

- [Tailwind form-How to create and style a Responsive Form using Tailwind CSS](https://www.devwares.com/blog/how-to-create-and-style-a-responsive-form-using-tailwindcss/)

- [Tailwind CSS Flex: How to use Tailwind CSS Flex](https://www.devwares.com/blog/how-to-use-tailwind-css-flex/)

- [How to use tailwind CSS padding, margin and border in your project](https://www.devwares.com/blog/how-to-use-tailwind-css-padding-margin-and-border-in-your-project/)

- [Tailwind CSS CDN-How to use the Tailwind CSS JIT CDN](https://www.devwares.com/blog/how-to-use-the-tailwind-css-JIT-CDN/)

- [How to set up your first Tailwind CSS Project](https://www.devwares.com/blog/setting-up-your-first-project-using-tailwind-css/)

- [How to use Tailwind CSS in HTML](https://www.devwares.com/blog/how-to-use-tailwind-css-in-HTML/)

- [Tailwind CSS table-How to Create Tailwind CSS tables](https://www.devwares.com/blog/how-to-create-tailwind-css-tables/)

- [How to set up your first Tailwind CSS Project](https://www.devwares.com/blog/setting-up-your-first-project-using-tailwind-css/)

- [Why is tailwind CSS better than other CSS framework](https://www.devwares.com/blog/why-tailwind-css-is-good/)

- [10 tailwind CSS templates and themes](https://www.devwares.com/blog/tailwind-css-10-templates-and-themes/)

- [How to add tailwind CSS colors and Fonts to your project](https://www.devwares.com/blog/how-to-add-tailwind-css-colors-and-fonts-to-your-project/)

- [Differences between Tailwind CSS and SASS](https://www.devwares.com/blog/differences-between-tailwind-css-and-sass/)

- [Differences Between Tailwind CSS and Bootstrap](https://www.devwares.com/blog/diffrences-between-tailwind-css-and-bootstrap/)

- [10 Awesome projects built with Tailwind CSS](https://www.devwares.com/blog/awesome-10-projects-built-with-tailwind/).

- [How to install Tailwind CSS in Vue.js](https://www.devwares.com/blog/how-to-install-tailwind-css-in-vuejs/).

- [How to use Tailwind CSS in React](https://www.devwares.com/blog/how-to-use-tailwind-css-in-react/)

- [How to install Tailwind CSS with Laravel](https://www.devwares.com/blog/how-to-install-tailwind-css-in-laravel/)

- [How to create react date picker](https://www.devwares.com/blog/create-datepicker-with-contrast/)

- [React bootstrap 5 form-How to create React forms](https://www.devwares.com/blog/how-to-create-and-style-a-responsive-form-using-tailwindcss/).

- [How to create a beautiful React multiselect](https://www.devwares.com/blog/create-multiselect-with-contrast/).

- [How to create a beautiful React Bootstrap progress bar](https://www.devwares.com/blog/create-progress-with-contrast/).

- [How to create a beautiful React Bootstrap select with icons](https://www.devwares.com/blog/create-select-with-contrast/).

- [How to create a beautiful Bootstrap 5 stepper](https://www.devwares.com/blog/create-stepper-with-contrast/)

- [How to create a beautiful React Bootstrap table]
(https://www.devwares.com/blog/create-tables-with-contrast/)

- [How to create beautiful React Bootstrap tabs](https://www.devwares.com/blog/create-tabs-with-contrast/)

- [How to create a Beautiful Responsive Navigation bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-create-a-beautiful-responsive-navbar-using-tailwind-css/)

- [Tailwind Modal-How to create a React Modal using Tailwind CSS.](https://www.devwares.com/blog/how-to-create-a-react-modal-using-tailwind-css/)

- [How to create a Bootstrap 5 Modal.](https://www.devwares.com/blog/how-to-create-a-bootstrap5-modal/)

- [How to create a beautiful Bootstrap Data table with Icons](https://www.devwares.com/blog/create-datatable-with-contrast/)

- [How to create a React date picker.](https://www.devwares.com/blog/create-datepicker-with-contrast/)

- [React bootstrap 5 form-How to create React forms](https://www.devwares.com/blog/create-forms-with-contrast/)
- [How to Create React Tabs with Tailwind CSS](https://www.devwares.com/blog/how-to-create-react-tabs-with-tailwind-css/)
- [How to implement dark mode in React using tailwind css](https://www.devwares.com/blog/how-to-implement-dark-mode-in-tailwind-css/)
- [How to Implement a React Step Progress Bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-implement-a-react-step-progress-bar-using-tailwind-css/)

- [Getting Started] (https://www.devwares.com/docs/contrast/react/index/)
- [Accordion](https://www.devwares.com/docs/contrast/react/components/accordion/)
- [Autocomplete](https://www.devwares.com/docs/contrast/react/components/autocomplete/)
- [Alert](https://www.devwares.com/docs/contrast/react/components/alert/)
- [Badges](https://www.devwares.com/docs/contrast/react/components/badge/)
- [Animation](https://www.devwares.com/docs/contrast/react/components/animations/)
- [Box](https://www.devwares.com/docs/contrast/react/components/box/)
- [ButtonToolbar](https://www.devwares.com/docs/contrast/react/components/buttonToolbar/)
- [Breadcrumb](https://www.devwares.com/docs/contrast/react/components/breadcrumb/)
- [ButtonGroup](https://www.devwares.com/docs/contrast/react/components/buttonGroup/)
- [Checkbox](https://www.devwares.com/docs/contrast/react/components/checkbox/)
- [Button](https://www.devwares.com/docs/contrast/react/components/buttons/)
- [Collapse](https://www.devwares.com/docs/contrast/react/components/collapse/)
- [Carousel](https://www.devwares.com/docs/contrast/react/components/carousel/)
- [Iframe](https://www.devwares.com/docs/contrast/react/components/iframe/)
- [Card](https://www.devwares.com/docs/contrast/react/components/card/)
- [DropDown](https://www.devwares.com/docs/contrast/react/components/dropdown/)
- [Footer](https://www.devwares.com/docs/contrast/react/components/footer/)
- [Input](https://www.devwares.com/docs/contrast/react/components/input/)
- [ListGroup](https://www.devwares.com/docs/contrast/react/components/listgroup/)
- [InputGroup](https://www.devwares.com/docs/contrast/react/components/inputgroup/)
- [Icon](https://www.devwares.com/docs/contrast/react/components/icon/)
- [Multiselect](https://www.devwares.com/docs/contrast/react/components/multiselect/)
- [Notification](https://www.devwares.com/docs/contrast/react/components/notification/)
- [Mask](https://www.devwares.com/docs/contrast/react/components/mask/)
- [Progress](https://www.devwares.com/docs/contrast/react/components/progress/)
- [Rating](https://www.devwares.com/docs/contrast/react/components/rating/)
- [Radio](https://www.devwares.com/docs/contrast/react/components/radio/)
- [Select](https://www.devwares.com/docs/contrast/react/components/select/)
- [Modal](https://www.devwares.com/docs/contrast/react/components/modal/)
- [Pane](https://www.devwares.com/docs/contrast/react/components/pane/)
- [Panel](https://www.devwares.com/docs/contrast/react/components/panels/)
- [Slider](https://www.devwares.com/docs/contrast/react/components/slider/)
- [Spinner](https://www.devwares.com/docs/contrast/react/components/spinner/)
- [Select 2](https://www.devwares.com/docs/contrast/react/components/select2/)
- [SmoothScroll](https://www.devwares.com/docs/contrast/react/components/smoothscroll/)
- [Switch](https://www.devwares.com/docs/contrast/react/components/switch/)
- [Stepper](https://www.devwares.com/docs/contrast/react/components/stepper/)
- [Charts](https://www.devwares.com/docs/contrast/react/chart/)
- [Navbar](https://www.devwares.com/docs/contrast/react/navigation/navbar/)
- [Tab](https://www.devwares.com/docs/contrast/react/navigation/tabs/)
- [Sidebar](https://www.devwares.com/docs/contrast/react/navigation/sidebar/)
- [Pagination](https://www.devwares.com/docs/contrast/react/navigation/pagination/)
- [DatePicker](https://www.devwares.com/docs/contrast/react/sections/datepicker/)
- [FileUploader](https://www.devwares.com/docs/contrast/react/sections/fileuploader/)
- [TimePicker](https://www.devwares.com/docs/contrast/react/sections/timepicker/)
- [EditableTable](https://www.devwares.com/docs/contrast/react/table/editabletable/)
- [Table](https://www.devwares.com/docs/contrast/react/table/table/)
- [DataTable](https://www.devwares.com/docs/contrast/react/table/datatables/)
- [Widgets](https://www.devwares.com/docs/contrast/react/widgets/)
- [Forms](https://www.devwares.com/docs/contrast/react/forms/)