How to create a beautiful tabs using bootstrap and Contrast
Tags: react, webdev, programming, tutorial
Published: 2021-08-02 11:09:15

---
title: How to create a beautiful tabs using bootstrap and Contrast
published: true
date: 2021-04-20 01:16:04 UTC
tags: [react, webdev, programming, tutorial]
canonical_url: https://www.devwares.com/blog//create-tabs-with-contrast
cover_image: https://devwares.com/blog/images/reactArticle1.png
---

## How to Create a beautiful tab component in react using bootstrap and Contrast.

Tabs are components which separate content placed in the same wrapper, but in the separate pane. Only one pane can be displayed at the time.
Today, we’ll be creating a tab in react using a react library knows as Contrast. Contrast also known as CDBReact is a react library which is an Elegant UI kit with full bootstrap support that has reusable components for building mobile-first, responsive websites, and web apps.
CDB Tabs are compatible with ReactRouter, meaning that `<NavLink>` components inside can be used both for one-page tabs and general routing solution for main navigation. Make sure to include the wrapping `<BrowserRouter>`.
If you are using navs to provide a navigation bar, be sure to add an appropriate role attributes to the `<NavLinks>` (role="tab").

**Prerequisites**

The tab would be built using React, Bootstrap, and CDBReact. You don’t need to have any previous knowledge of CDBReact but the following are necessary:
- JavaScript Knowledge
- Basic React Knowledge
- Basic Bootstrap Knowledge
- JavaScript Knowledge
- NPM installed

The tab we are going to build requires the pro version and it will look like the image below

![Tabs](./images/tab.png)


Setup
First Check that you have node installed. To do this, run the following command in your terminal.

```javascript
node -v
```

This should show you the current version of node you have installed on your machine.
If you don’t have node.js installed, download it here.
Installing node also installs npm on your PC but you can still confirm using 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 tab-app
```

I named the project tab-app but you can use whatever name of your choice.

## Installing CDBReact-pro

Before we install our CDBReact we have to download the pro version first. Then, we can go ahead to install them in our project. It is advised to add the file to the root of the project by running.

```javascript
npm install --save ./path-to-the-cdbreact-pro-tgz-file
```

Or using Yarn

```javascript
yarn add ./path-to-the-cdbreact-pro-tgz-file
```


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

Our tab would be making use of the Navlink component from React router, so let us install it by running the command below.

Code:

```javascript
npm install react-router-dom
```

Now run `npm start` to make sure that everything works well and there are no errors.
Before we proceed, let’s go ahead and wrap our app with the BrowserRouter component from react-router-dom as Navlinks can’t work outside it.

**Code:**

```html
import './App.css';
import Tab from './tab';
import { BrowserRouter as Router } from 'react-router-dom';

function App() {
  return (
    <Router>
      <div className="App">

      </div>
    </Router>
  );
}

export default App;

```

**TAB**

At the stage we will have to create a file named tab.js which would contain our Tab component. Import the various tab components that we’ll be using.

**Code:**

```html
import React from "react";
import { CDBNav, CDBTabLink, CDBTabContent, CDBTabPane, CDBContainer } from "cdbreact";
import { NavLink } from react-router-dom;

```

in the file above, we imported some CDBReact for the tab.
-CDBNav for the navigation of the web.
-CDBTabLink for links in the tab.
-CDBTabContent contains the main body of the tab.
-CDBTabPane contains the pane of the tab.
-CDBContainer wraps the entire components of the tab.


**Code:**

```html
const Tab = () => {
  return (
    <CDBContainer>
        <CDBContainer>
          <CDBNav className="nav-tabs mt-5">
            <CDBTabLink
              link
              to="#"
              active={this.state.activeItem === "1"}
              onClick={this.toggle("1")}
              role="tab"
            >
              Label 1
            </CDBTabLink>

            <CDBTabLink
              link
              to="#"
              active={this.state.activeItem === "2"}
              onClick={this.toggle("2")}
              role="tab"
            >
              Label 2
            </CDBTabLink>
            <CDBTabLink
              link
              to="#"
              active={this.state.activeItem === "3"}
              onClick={this.toggle("3")}
              role="tab"
            >
              Label 3
            </CDBTabLink>
          </CDBNav>
          <CDBTabContent activeItem={this.state.activeItem}>
            <CDBTabPane tabId="1" role="tabpanel">
              <p className="mt-2">
                Lorem ipsum dolor sit amet, consectetur adipisicing elit.
                Nihil odit magnam minima, soluta doloribus reiciendis
                molestiae placeat unde eos molestias. Quisquam aperiam,
                pariatur. Tempora, placeat ratione porro voluptate odit
                minima.
              </p>
            </CDBTabPane>
            <CDBTabPane tabId="2" role="tabpanel">
              <p className="mt-2">
                Quisquam aperiam, pariatur. Tempora, placeat ratione porro
                voluptate odit minima. Lorem ipsum dolor sit amet,
                consectetur adipisicing elit. Nihil odit magnam minima,
                soluta doloribus reiciendis molestiae placeat unde eos
                molestias.
              </p>
              <p>
                Quisquam aperiam, pariatur. Tempora, placeat ratione porro
                voluptate odit minima. Lorem ipsum dolor sit amet,
                consectetur adipisicing elit. Nihil odit magnam minima,
                soluta doloribus reiciendis molestiae placeat unde eos
                molestias.
              </p>
            </CDBTabPane>
            <CDBTabPane tabId="3" role="tabpanel">
              <p className="mt-2">
                Quisquam aperiam, pariatur. Tempora, placeat ratione porro
                voluptate odit minima. Lorem ipsum dolor sit amet,
                consectetur adipisicing elit. Nihil odit magnam minima,
                soluta doloribus reiciendis molestiae placeat unde eos
                molestias.
              </p>
            </CDBTabPane>
          </CDBTabContent>
        </CDBContainer>
    </CDBContainer>
  );
};
export default Tab;
```

In the code above, we used CDBNav, CDBTabLink, CDBTabContent, CDBTabPane, CDBContainer to create the tab, add contents with some bootstrap styling which beautifies the tab.
Let us go ahead to import the created tab component into our app component

**Code:**

```html
import './App.css';
import Tab from './tab';
import { BrowserRouter as Router } from 'react-router-dom';

function App() {
  return (
    <Router>
      <div className="App">
       <Tab />
      </div>
    </Router>
  );
}

export default App;

```

The tab we created will look like the image below 

![Tabs](./images/tab.png)
 

**Conclusion**

Building a tab using contrast is quite simple and allows you to use several tools including bootstrap styling without installing bootstrap to create your tab. You can also  check out some other features you can use in CDBReact Tab Docs . you can also check the code here in our github.



###Create Stunning Websites and Web Apps

Building different custom components in react for your web apps or websites can get very stressful. Thats 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 

- [Link to the Github Code](https://github.com/Iheanacho-ai/Tailwind-react-modal)

- [Link to the Tailwind CSS Modals Docs](https://tailwindui.com/components/application-ui/overlays/modals)

- [Get Tailwind CSS PRO](https://tailwindui.com/pricing)

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

- [Link to the modal documentation](https://www.devwares.com/docs/contrast/javascript/components/modal)

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

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

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

- [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 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/)