The Most Popular Navigation Bars created with Flexbox

Ohans Emmanuel
Jul 15, 2017 · 5 min read

This is a simple but practical article. The aim is to build the navigation bars for facebook twitter github and medium with Flexbox. Facebook and Twitter are arguably the most popular websites in the world. Hence, the most popular navigation bars in the world :-)

Getting Started

The first step is to create some sort of container to house the navigation bars we will be making. When done, it should look like this:

first step.

Let’s get started.

First, create a basic html document to house the navigation bars.

Pretty simple. A main section to act as the container. The navigation bars will seat within their respective containers too.

Let’s add a bit of styling.

To keep the main section in the center of the page, do this:

Also, give main section a bit of style. No one loves ugly designs. Aaargh!

And here’s what we have:

current state of things.

Yeah! Now we’ve got something on the screen.


Let’s start creating the first navigation bar, twitter!

Why Twitter first? Not Facebook? I have no legit reason. I just feel like :-) Or maybe because I haven’t used facebook in a long time!

The official Twitter navigation bar looks like this:

Let’s structure the html document for glory!

So, if I read your thoughts, this is how you think we’ll structure the document, right? Three div of some sort?

if you were gong to use `floats`

Hell no!

For simplicity, and to really take control of some flexbox goodies, I’ll use an unordered list ul. This means the nav tags will be changed to ul tags.

A list item li for each element within the navigation bar. I have gone ahead to add role=navigation for accesibility.

Flesh out the basic markup, like this:

I know it looks complex, but it is a very simple document. A bunch of li tags with icons in i tags. These icons are got from font awesome. This will save us a lot of stress, and keep these examples simple.

At this point this is what you should have:

basic setup for twitter.

I have gone ahead to increase the width of the main section.

Now we can move on to some CSS goodness 😄

Clear the unneccessary spacing and list style from the unonderlist list:

Now, the twitter navigation should seat on the same line as the rest of the contents in the container. Oh, and without the ugly list dots too.

after removing the undue spacing and list style.

Now, let’s get Flexbox unto the scene. Aye! Been waiting for this:

The flexbox magic!

The sweet spot of this particular navigation comes next. How do you make sure the twitter bird (or whatever it is called) stays at the center?

Use Flexbox!

Target the list item containing the twitter bird. This is because the list li represents the flex-item

Give it a class so we can make reference to it via CSS.

Now make magic!

That’s it!

Believe me, that is all the Flexbox you need. 3 lines of Flexbox!

If you aren’t familiar with the flexbox auto margin trick, i wrote an article that explains everything you need to know here.

If you clean up the UI a bit, you’ll have the navigation looking good. Just like this:

good looking, huh?

If you spend a lot more on styling the navigation bar, you will have it looking better.

Here’s the bit of “extra” styling I wrote:


Now let’s create the Facebook navigation bar. Let’s make Zuck happy.

The official navigation bar looks like this:

facebbok navigation bar

As always, start with a basic html document. An unordered list with a couple list elements.

basic setup for the facebook navigation bar. Becasue I copied and pasted (who doesn’t?) the input field reads, “search twitter” instead of “seach facebook”

Here is all the code at this point:

Let’s style this.

As always, It all begins with a one liner:

flexbox initiated for the facebook navigation.

Target the facebook search form and get flexbox in action.

flexbox in action

Haha. That my dear is all the flexbox you need!

If you spend some more time, the UI will be polished. Something like this:

Here is all the “extra” styling I wrote:


The entire code lives here:

If you want to practice the concepts learned, I advice you try to build the navigation bars for Medium and Github. You’ll find it interesting.


I have been learning Spanish! So, I’ll say “thank you very much” in spanish

muchas gracias

Thanks for following along.

Want to become Pro?

Download my free CSS Grid cheat sheet, and also get two quality interactive Flexbox courses for free!

Get the Free CSS Grid Cheat sheet + Two Quality Flexbox Courses for free!

Get them now

Flexbox and Grid

Want to master Flexbox or the CSS Grid? Get in Line!

Ohans Emmanuel

Written by

I build complex frontends. I’m passionate about teaching intricate subjects e.g. Now writing here:

Flexbox and Grid

Want to master Flexbox or the CSS Grid? Get in Line!

Ohans Emmanuel

Written by

I build complex frontends. I’m passionate about teaching intricate subjects e.g. Now writing here:

Flexbox and Grid

Want to master Flexbox or the CSS Grid? Get in Line!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store