How To Create A Beautiful Navbar Using Bootstrap And Contrast
Tags: webdev, react, programming, codenewbie
Published: 2021-03-28 05:43:44

---
title: How To Create A Beautiful Navbar Using Bootstrap And Contrast
published: true
date: 2021-01-20 01:16:04 UTC
tags: [webdev, react, programming, codenewbie]
canonical_url: https://www.devwares.com/blog//bootstrap-5-navbar-using-contrast
---

![Bootstrap Navbar](https://www.devwares.com/blog/images/bootstrap-navbar-with-contrast.png)


A navigation bar, which is often called a navbar, is one of, if not the most important, components or elements of a website. This is so because it usually is the first thing a person searches for when they’re on a website as it lets them properly navigate through the website because it links to the other pages the website has to offer.


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

A poorly constructed navigation bar or navbar heavily impacts the overall experience a person gets from using a website whereas A BEAUTIFUL NAVBAR makes the experience of using a website a pleasant and enjoyable one.

  

This article aims to describe, step by step, how to build a functional and beautiful navbar using bootstrap 5 and a cool new UI kit called Contrast.

**FIRST OFF:**

Let me refresh our minds on what bootstrap is. Bootstrap is one of, if not the most popular CSS Framework/front-end open-source toolkit for developing responsive and mobile-first websites.

It features Sass variables, mixins, a responsive grid system, extensive prebuilt components, and powerful JavaScript plugins. Bootstrap's newest version is Bootstrap 5.

You can say Bootstrap helps you build responsive websites quickly. Now I’m sure at this point you might be asking yourself, “What is Contrast?” Do not worry, the wait is over.

**CONTRAST**

Contrast or Contrast Design Bootstrap is an elegant bootstrap UI kit featuring over 2000+ basic components. Contrast can be integrated with any project to build mobile-first, responsive, and elegant websites and web apps.

With Contrast installed, installing Bootstrap no longer becomes a necessity because Bootstrap is deeply integrated into its core. Plus, Contrast brings its 2000+ custom components to the table, making development smooth and elegant. Contrast, which was created by Devwares is available for the following technologies;

1. Vanilla JS [(contrast-bootstrap)](https://www.devwares.com/docs/contrast/javascript/components/alert)
2. React [(cdbreact)](https://www.devwares.com/docs/contrast/react/installation)
3. Angular [(ng-cdbangular)](https://www.devwares.com/docs/contrast/angular/installation)

Devwares also designed a Pro version of Contrast to give you access to more features and improvements.

Click [here](https://www.devwares.com/resources#premium) to check it out.

We will be using the [angular](https://www.devwares.com/docs/contrast/angular/installation) version of contrast in this tutorial to create the navbar. Tutorials for other versions can also be found on the docs [here](https://www.devwares.com/docs/contrast/javascript/components/alert)

**Now that all that’s been taken care off, let’s find out how to create a beautiful navbar using bootstrap 5 and contrast (Angular).**

**STEP 1** Install Contrast Using NPM:

```bash
npm install --save ng-cdbangular

```

Using Yarn:

```bash
 yarn add ng-cdbangular

```

**STEP 2** Add bootstrap-css-only to angular.json

```javascript
"styles": ["node_modules/bootstrap-css-only/css/bootstrap.min.css"]

```

STEP 3 Import navbar module in app.module.ts

```javascript
import { NavbarModule } from 'ng-cdbangular';
@NgModule({ imports: [NavbarModule]})

```

NB, for our example, we will be needing some other components so our final app.module.ts file will look like this;

```javascript
    import { 
    NavbarModule, 
    CollapseModule,  
    ButtonModule, 
    DropdownModule } from 'ng-cdbangular';
    @NgModule({  
        imports: [NavbarModule, CollapseModule, ButtonModule, DropdownModule]
    })

```

**Note:** instead of importing one component at a time, contrast has a module called CDBFreeModule which contains the imports of all the custom components contrast has to offer.

```javascript
import { CDBFreeModule } from 'ng-cdbangular';
@NgModule({ imports: [CDBFreeModule]})

```

Easy right? Now let’s dive right into the view.

**HTML VIEW**

A basic Contrast navbar looks like this:

```javascript
<CDBNavbar style="background: black; color: #f4f4f4">   
 <a href="">link</a>
 </CDBNavbar>

```

[![Bootstrap Navbar](https://www.devwares.com/static/b891db4bf761c5113c1b3a5003a8db7d/eafa0/navbar1.png "Bootstrap Navbar")](/static/b891db4bf761c5113c1b3a5003a8db7d/eafa0/navbar1.png)

This looks... okay, but I know we can do better. Let’s add the CDBNavBrand component for brand logos and the likes

```javascript
<CDBNavbar style="background: black; color: #f4f4f4">
<CDBNavBrand href="/">
<img src="" alt="Brand" class="img-fluid" width="30">
</CDBNavBrand>
</CDBNavbar>

```

Note that the contents of CDBNavBrand can be anything you want eg:

`<h4>Brand<h4>`

[![Bootstrap Navbar](https://www.devwares.com/static/77cabec0983d2745086c511fffc26220/eafa0/navbar2.png  "Bootstrap Navbar")](/static/77cabec0983d2745086c511fffc26220/eafa0/navbar2.png)

Now, Let’s make the navbar responsive.

```javascript
<CDBNavbar style="background: black; color: #f4f4f4" [dark]=true expand="lg">
<CDBNavBrand href="/">   
 <img src="" alt="Brand" class="img-fluid" width="30">
 </CDBNavBrand> 
 <CDBNavToggle (click)="myNav.toggleCollapse()">
 </CDBNavToggle>
 <CDBCollapse #myNav class="w-100" [navbar]=true expand="lg">  
    Lorem, ipsum dolor sit amet consectetur adipisicing elit. Aut, minus?
</CDBCollapse>
</CDBNavbar>

```

[![Bootstrap Navbar](https://www.devwares.com/static/ba4db9df1955866a7382a7d1d48b83f8/eafa0/navbar3.png "Bootstrap Navbar")](/static/ba4db9df1955866a7382a7d1d48b83f8/eafa0/navbar3.png)

[![Bootstrap Navbar](https://www.devwares.com/static/a71898ab8c59d5bd76503447c88e8d36/23296/navbar4.png "Bootstrap Navbar")](/static/a71898ab8c59d5bd76503447c88e8d36/23296/navbar4.png)

[![Bootstrap Navbar](https://www.devwares.com/static/59aa19cad26394ba889bf73d763e252a/23296/navbar5.png "Bootstrap Navbar")](/static/59aa19cad26394ba889bf73d763e252a/23296/navbar5.png)

This example introduced more custom components. Let’s go through them one step at a time.

1. The expand prop was added to the CDBNavbar component. expand="lg" tells the navbar to collapse when the viewport width is < 992px. 

Acceptable breakpoints include:

- sm = collapse when the viewport width is < 576px
- md = collapse when the viewport width is < 768px
- lg = collapse when the viewport width is < 992px
- xl = collapse when the viewport width is < 1200px

[dark]=true was added because the background color is dark. [light]=true should be used when a lighter background is used.

1. The CDBNavToggle component was added. This is Contrasts navigation bar toggler. It becomes visible only when the viewport width is lower than the specified breakpoint you put in the “expand” prop.

2. A click event handler was added to CDBNavToggle component:``` (click)="myNav.toggleCollapse()".``` CDBNavToggle is accessing the toggleCollapse() function present in CDBCollapse in order to collapse the navigation bar programmatically through the local reference “myNav”.

Note: an image prop can be added to the CDBNavToggle in place on the default toggler eg:

```javascript
 <CDBNavToggle (click)="myNav.toggleCollapse()" image=""></CDBNavToggle>

```

[![Bootstrap Navbar](https://www.devwares.com/static/5f3153390346ea1265ea221556df3ed1/23296/navbar6.png "Bootstrap Navbar")](/static/5f3153390346ea1265ea221556df3ed1/23296/navbar6.png)

Here I’m using a literal hamburger :)

1. 

The CDBCollapse component was added. This is the actual component that collapses the navigation bar. A local reference of #myNav is added so that the toggler can access its toggleCollapse function. [navbar]=true is used to inform the collapse that this instance is being used as a navigation bar.expand=”lg”, this is added to tell CDBCollapse when to collapse. Note that the same breakpoint used in the CDBNavbar component must also be used here.

  

Whew! Alright, now that the navbar is responsive and ready to go, let’s add some flesh to it. We’ll be making use of some other Contrast components.

```javascript
<CDBNavbar style="background: black; color: #f4f4f4" [dark]=true expand="lg">
    <CDBNavBrand href="/">
        <img src="" alt="Brand" class="img-fluid" width="30"/>   
    </CDBNavBrand>    
    <CDBNavToggle (click)="myNav.toggleCollapse()" > </CDBNavToggle>
    <CDBCollapse #myNav class="w-100" [navbar]=true expand="lg">
        <CDBNavbarNav [left]=true class="align-items-center">     
        <CDBNavItem>              
        <CDBDropDown>           
            <CDBDropDownToggle [caretDropDown]=true style="padding: 0" 
            color="dark" (click)="menu.toggleDropdown($event)"> 
            Categories 
            </CDBDropDownToggle>     
        <CDBDropDownMenu #menu="cdbDropdownMenu" placement="bottom">
        Coming soon #pleaseStayUpdated. 
        </CDBDropDownMenu> 
        </CDBDropDown> 
        </CDBNavItem>     
        <CDBNavItem>
            <CDBBtn [flat]=true color="dark" style="padding: 0">
            <CDBNavLink to="/" style="color: #ffffff">Help</CDBNavLink> 
        </CDBBtn>
        </CDBNavItem>
        <CDBNavItem>
            <CDBBtn [flat]=true color="dark" style="padding: 0">
            <CDBNavLink to="/" style="color: #ffffff">About</CDBNavLink>
            </CDBBtn>           
        </CDBNavItem>     
        </CDBNavbarNav>
        <CDBNavbarNav [right]=true> 
           <CDBNavItem>
            <CDBBtn [flat]=true color="dark" style="padding: 0">
                <CDBNavLink to="/" style="color: #ffffff">EN</CDBNavLink> 
            </CDBBtn>
            </CDBNavItem>
           <CDBNavItem>
            <CDBBtn [flat]=true color="dark" style="padding: 0">
                <CDBNavLink to="/" style="color: #ffffff">Login</CDBNavLink> 
            </CDBBtn> 
            </CDBNavItem>
            <CDBNavItem> 
            <CDBBtn color="white" style="padding: 0"> 
                <CDBNavLink to="/" style="color: #000000;"> Sign Up </CDBNavLink>
            </CDBBtn>
            </CDBNavItem>
        </CDBNavbarNav>
    </CDBCollapse>
</CDBNavbar> 

```

[![Bootstrap Navbar](https://www.devwares.com/static/df3484a5052187e43aae8eb720a482a5/eafa0/navbar7.png "Bootstrap Navbar")]
(static/df3484a5052187e43aae8eb720a482a5/eafa0/navbar7.png)

[![Bootstrap Navbar](https://www.devwares.com/static/954419db1024f97e791b81a8b08812a4/23296/navbar8.png "Bootstrap Navbar")]

(/static/954419db1024f97e791b81a8b08812a4/23296/navbar8.png)

That is the final result of what our navbar should look like and you can definitely style the components more anyway you wish to.

You can find more information on all the components used in the navbar in the [documentation](https://www.devwares.com/docs/contrast/angular/navigation/navbar)

###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 

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

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

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

- [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 use Tailwind CSS Width](https://www.devwares.com/blog/Tailwind-width/)
- [Tailwind CSS Colors 3.0](https://www.devwares.com/blog/How-to-add-color-to-Tailwind/)
- [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/)