How to create: Navigation bar with icons

Learn how to create a responsive navigation bar with icons using CSS.

Navigation bar with icons

Try It Yourself

Create a responsive navigation bar with icons

Step 1 - Add HTML:

Load an icon library
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="navbar">
  <a class="active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>
  <a href="#"><i class="fa fa-fw fa-search"></i> Search</a>
  <a href="#"><i class="fa fa-fw fa-envelope"></i> Contact</a>
  <a href="#"><i class="fa fa-fw fa-user"></i> Login</a>
</div>

Second step - Add CSS:

/* Set the style of the navbar */
.navbar {
  width: 100%;
  background-color: #555;
  overflow: auto;
}
/* Navbar link style */
.navbar a {
  float: left;
  text-align: center;
  padding: 12px;
  color: white;
  text-decoration: none;
  font-size: 17px;
}
/* Navbar link style on hover */
.navbar a:hover {
  background-color: #000;
}
/* Current/active navbar link */
.active {
  background-color: #04AA6D;
}
/* Add responsiveness - on screens less than 500 pixels, the navbar will be displayed vertically automatically instead of horizontally */
@media screen and (max-width: 500px) {
  .navbar a {
    float: none;
    display: block;
  }
}

Try It Yourself

Related Pages

Tutorial:CSS Navigation Bar

Tutorial:How to Create Icon Navigation Bar