Bootstrap NavBar with left, center or right aligned items

In Bootstrap, what is the most platform-friendly way to create a navigation bar that has Logo A on the left, menu items in the center, and Logo B on the right?

Here is what I've tried so far, and it ends up being aligned so that Logo A is on the left, menu items next to the logo on the left and Logo B on the right.

<div> <div > <div> <button type="button"> <span></span> <span></span> <span></span> </button> <a href="#"><span>Logo_A</span></a> </div> <div> <ul> <li><a href="#">Home</a></li> <li><a href="#about">Menu Item 1</a></li> <li><a href="#contact">Menu Item 2</a></li> <li><a href="#about">Menu Item 3</a></li> </ul> <ul> <li><a href="#"><img src="images/Logo_B.png"></a></li> </ul> </div> </div> </div> 

14 Answers

2021 Update

Bootstrap 5 (beta)

Bootstrap 5 also has a flexbox Navbar, and introduces new RTL support. For this reason the concept of "left" and "right" has been replaced with "start" and "end". Therefore the margin utilities changed for Bootstrap 5 beta:

  • ml-auto => ms-auto
  • mr-auto => me-auto

Also note that data-toggle and data-target have changed too:

  • data-toggle => data-bs-toggle
  • data-target => data-bs-target

Navbar Demo for Bootstrap 5

Bootstrap 4

Now that Bootstrap 4 has flexbox, Navbar alignment is much easier. Here are updated examples for left, right and center in the Bootstrap 4 Navbar, and many other alignment scenarios demonstrated here.

The flexbox, auto-margins, and ordering utility classes can be used to align Navbar content as needed. There are many things to consider including the order and alignment of Navbar items (brand, links, toggler) on both large screens and the mobile/collapsed views. Don't use the grid classes (row,col) for the Navbar.

Here are various examples...

Left, center(brand) and right links:

enter image description here

<nav> <div> <ul> <li> <a href="#">Left</a> </li> <li> <a href="//codeply.com">Codeply</a> </li> <li> <a href="#">Link</a> </li> <li> <a href="#">Link</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> <div> <a href="#">Navbar 2</a> <button type="button"> <span></span> </button> </div> <div> <ul> <li> <a href="#">Right</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> </nav> 


Another BS4 Navbar option with center links and overlay logo image:

center links and overlay logo image

<nav> <div> <ul> <li> <a href="#">Link</a> </li> </ul> </div> <div> <a href="#"> <img src="//"> </a> <button type="button"> <span></span> </button> </div> <div> <ul> <li> <a href="#">Link</a> </li> </ul> </div> </nav> 

Or, these other Bootstrap 4 alignment scenarios:

brand left, dead center links, (empty right)

Navbar brand left, dead center links


brand and links center, icons left and right

enter image description here


More Bootstrap 4 examples:

toggler left on mobile, brand right
center brand and links on mobile
right align links on desktop, center links on mobile
left links & toggler, center brand, search right


Also see: Bootstrap 4 align navbar items to the right
Bootstrap 4 navbar right align with button that doesn't collapse on mobile
Center an element in Bootstrap 4 Navbar


Bootstrap 3

Option 1 - Brand center, with left/right nav links:

enter image description here

<nav> <div> <button type="button"> <span></span> <span></span> <span></span> </button> </div> <a href="#">Brand</a> <div> <ul> <li><a href="#">Left</a></li> <li><a href="#about">Left</a></li> </ul> <ul> <li><a href="#about">Right</a></li> <li><a href="#contact">Right</a></li> </ul> </div> </nav> .navbar-brand { position: absolute; width: 100%; left: 0; text-align: center; margin:0 auto; } .navbar-toggle { z-index:3; } 

(3.x)


Option 2 - Left, center and right nav links:

enter image description here

<nav> <div> <button type="button"> <span></span> <span></span> <span></span> </button> </div> <div> <ul> <li><a href="#">Left</a></li> </ul> <ul> <li><a href="#">Center</a></li> <li><a href="#">Center</a></li> <li><a href="#">Center</a></li> </ul> <ul> <li><a href="#">Right</a></li> </ul> </div> </nav> @media (min-width: 768px) { .navbar-nav.navbar-center { position: absolute; left: 50%; transform: translatex(-50%); } } 

Option 3 - Center both brand and links

enter image description here

.navbar .navbar-header, .navbar-collapse { float:none; display:inline-block; vertical-align: top; } @media (max-width: 768px) { .navbar-collapse { display: block; } } 

More examples:

Left brand, center links
Left toggler, center brand

For 3.x also see nav-justified: Bootstrap center navbar


Center Navbar in Bootstrap
Bootstrap 4 align navbar items to the right

9

Bootstrap 4

We have many ways to align navBars Items.

For Left Align enter image description here

class = "navbar-nav mr-auto"

For Right Align enter image description here

class = "navbar-nav ml-auto"

For Center Align enter image description here

class = "navbar-nav mx-auto"

<nav> <a routerLink="/" href="#">Bootstrap 4</a> <ul> <li> <a href="home">Home</a> </li> <li> <a href="about">About</a> </li> <li> <a href="contact">Contact us</a> </li> </ul> </nav> 
1

I needed something similar (left, center and right aligned items), but with ability to mark centered items as active. What worked for me was:

<nav> <div> <button type="button"> <span></span> <span></span> <span></span> </button> </div> <div> <ul> <li><a href="#">Left 1</a></li> <li><a href="#">Left 2</a></li> <li><a href="#">Center 1</a></li> <li><a href="#">Center 2</a></li> <li><a href="#">Center 3</a></li> <li><a href="#">Right 1</a></li> <li><a href="#">Right 2</a></li> </ul> </div> </nav> 

CSS:

@media (min-width: 768px) { .navbar-nav { width: 100%; text-align: center; } .navbar-nav > li { float: none; display: inline-block; } .navbar-nav > li.navbar-right { float: right !important; } } 
4

Bootstrap 4 (as of alpha 6)

Navbars are built with flexbox! Instead of floats, you’ll need flexbox and margin utilities.

For Align Right use justify-content-end on the collapse div:

<div> <ul> <li> <a href="#">Home</a> </li> </ul> </div> 

Full example here:

4

Smack my head, just reread my answer and realized the OP was asking for two logo's one on the left one on the right with a center menu, not the other way around.

This can be accomplished strictly in the HTML by using Bootstrap's "navbar-right" and "navbar-left" for the logos and then "nav-justified" instead of "navbar-nav" for your UL. No addtional CSS needed (unless you want to put the navbar-collapse toggle in the center in the xs viewport, then you need to override a bit, but will leave that up to you).

<nav> <div> <button type="button"> <span></span> <span></span> <span></span> </button> <div><a href="#"><img src=""></a></div> </div> <div><a href="#"><img src=""></a></div> <div> <ul> <li><a href="#">home</a></li> <li><a href="#about">about</a></li> </ul> </div> </nav> 

Bootply:


For those who got here trying to center the "brand" here is my old answer:

I know this thread is a little old, but just to post my findings when working on this. I decided to base my solution on skelly's answer since tomaszbak's breaks on collaspe. First I created my "navbar-center" and turned off float for the normal navbar in my CSS:

.navbar-center { position: absolute; width: 100%; left: 0; text-align: center; margin: auto; } .navbar-brand{ float:none; } 

However the issue with skelly's answer is if you have a really long brand name (or you wanted to use an image for your brand) then once you get to the the sm viewport there could be overlapping due to the absolute position and as the commenters have said, once you get to the xs viewport the toggle switch breaks (unless you use Z positioning but I really didn't want to have to worry about it).

So what I did was utilize the bootstrap responsive utilities to create multiple version of the brand block:

<nav> <div> <button type="button"> <span></span> <span></span> <span></span> </button> <div><a href="#">Brand That is Really Long</a></div> </div> <div><a href="#">Brand That is Really Long</a></div> <div><a href="#">Brand That is Really Long</a></div> <div> <ul> <li><a href="#">Left</a></li> <li><a href="#about">Left</a></li> <li><a href="#">Left</a></li> <li><a href="#about">Left</a></li> <li><a href="#">Left</a></li> <li><a href="#about">Left</a></li> </ul> <ul> <li><a href="#about">Right</a></li> <li><a href="#contact">Right</a></li> <li><a href="#about">Right</a></li> <li><a href="#contact">Right</a></li> <li><a href="#about">Right</a></li> <li><a href="#contact">Right</a></li> </ul> </div> 

So now the lg and md viewports have the brand centered with links to the left and right, once you get to the sm viewport your links drop to the next line so that you don't overlap with your brand, and then finally at the xs viewport the collaspe kicks in and you are able to use the toggle. You could take this a step further and modify the media queries for the navbar-right and navbar-left when used with navbar-brand so that in the sm viewport the links are all centered but didn't have the time to vet it out.

You can check my old bootply here:

I guess having 3 brands might be just as much hassle as the "z" but I feel like in the world of responsive design this solution fits my style better.

You set the margin left to auto -> ml-auto on the section you want to move to the right.

 <nav> <a href="#">Navbar</a> <button type="button" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> <span></span> </button> <div> <div> !<--MARGIN LEFT AUTO HERE !--> <a href="#">Home <span>(current)</span></a> <a href="#">Features</a> <a href="#">Pricing</a> <a href="#" tabindex="-1" aria-disabled="true">Disabled</a> </div> </div> 

this is an update for BS5 and a suggested edit for @Zim's answer. Unfortunately I can't submit the edit as the edit queue is full. It would be good if a user with high reputation could submit the edit once the queue allows new edits.

2021 Update

Bootstrap 5.0.0 beta-1

With the addition of RTL-support, ml-auto and mr-auto become ms-auto and me-auto (left/right to start/end).

Bootstrap 5 also requires the navbar to be contained inside a container div.

This code produces the equivalent of the first Bootstrap 4 example:

Left, center(brand) and right links:

enter image description here

<nav> <div> <div> <ul> <li> <a href="#">Left</a> </li> <li> <a href="//codeply.com">Codeply</a> </li> <li> <a href="#">Link</a> </li> <li> <a href="#">Link</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> <div> <a href="#">Navbar 2</a> <button type="button"> <span></span> </button> </div> <div> <ul> <li> <a href="#">Right</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> </div> </nav> 
2

In bootstrap 5 ms-auto worked for me to move the nav items right

the code of bootstrap was:

 <nav> <div> <a href="#">Navbar</a> <button type="button" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span></span> </button> <div> <ul> <li> <a aria-current="page" href="#">Home</a> </li> <li> <a href="#">Features</a> </li> <li> <a href="#">Pricing</a> </li> <li> <a>Disabled</a> </li> </ul> </div> </div> </nav> 

I changed at ul tag <ul> to <ul> and it's worked fine for me

my code after editing is :

 <nav> <div> <a href="#">Cooking Master</a> <button type="button" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span></span> </button> <div> <ul> <li> <a aria-current="page" href="#">Home</a> </li> <li> <a href="#">Features</a> </li> <li> <a href="#">Pricing</a> </li> <li> <a href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav> 

In bootstrap 5 the classes are changed, so for ml-auto is changes with ms-auto AND mr-auto is changes with me-auto

For left we have to use s instead of l, And For Right we have to use e instead of r

I found the following was a better solution depending on the content of your left, center and right items. A width of 100% without a margin caused overlapping of divs and was preventing anchor tags to work correctly - that is without the messy use of z-indexes.

.navbar-brand { position: absolute; width: 100%; left: 0; margin: auto; margin-left: 48%; } 
0

This is a dated question but I found an alternate solution to share right from the bootstrap github page. The documentation has not been updated and there are other questions on SO asking for the same solution albeit on slightly different questions. This solution is not specific to your case but as you can see the solution is the <div> right after <nav> but can also be replaced with <div as needed.

<!DOCTYPE html> <html> <head> <title>Navbar right padding broken </title> <script src="//"></script> <script src=""></script> <link rel="stylesheet" href="//" /> </head> <body> <nav> <div> <div> <button type="button"> <span>Toggle navigation</span> <span></span> <span></span> <span></span> </button> <a href="#/">Hello</a> </div> <div> <ul> <li> <div aria-label="..."> <button type="button">Se connecter</button> <button type="button">Créer un compte</button> </div> </li> </ul> </div> </div> </nav> </body> </html> 

The solution was found on a fiddle on this page:

and is listed as a won't fix in V3.

<div>hello</div> <div>hello</div> <div>hello</div> <div>hello</div> <div>hello</div> 

Put the fields that you want to center, right or left according above division.

In Zim's answer the example 5 left and center only with empty space right is not really centering the navlinks. We can fix it using a few changes:

<link href="" rel="stylesheet" /> <p>Zim's original code</p> <!-- example 5 left and center only with empty space right --> <nav> <div> <button type="button"> <span></span> </button> <span>Navbar 5</span> <div> <ul> <li> <a href="#">Link</a> </li> <li> <a href="#">Codeply</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> <div> <!--spacer--> </div> </div> </nav> <div>mid</div> <br><br><br> <p>Modified solution</p> <!-- example 5 left and center only --> <nav> <!-- 2.5rem is height of the toggler --> <div> <span> <button type="button"> <span></span> </button> Navbar 5 </span> <div> <ul> <li> <a href="#">Link</a> </li> <li> <a href="#">Codeply</a> </li> <li> <a href="#">Link</a> </li> </ul> </div> </div> </nav> <div>mid</div> <style> body { font-family: monospace; padding: 10px } .centerMarker { margin: 0 auto; width: fit-content; background-color: wheat; } </style>

Switch to full page and resize browser to see navlinks.

Bootstrap doesn't allow us to set flex-basis:0, so the property remains auto and the spacer doesn't expand equally. So the navlinks are not centered.

We can use class position-absolute on brand container and mx-auto w-100 on navlinks. The toggler sets the min height of the navbar to 2.5rem. That we have to set to the fluid div container.

The simplest solution:

Just divide the navbar into columns: for instance, if you have 24 columns over all, 12 are going to be empty and 12 are going to contrain the navbar:

<nav> <div> <div></div> <div></div> <div></div> <div> <ul align="center"> <li><a href="#">Home</a></li> <li><a href="#">First Link</a></li> <li><a href="#">Second Link</a></li> <li><a href="#">Third Link</a></li> <li><a href="#">Fourth Link</a></li> </ul> </div> </div> </nav> 
2

You Might Also Like