How to create: Right-aligned menu button

Learn how to create a navigation bar with left-aligned and right-aligned links.

Try It Yourself

Create a top navigation bar

Step 1 - Add HTML:

<div class="topnav">
  <a class="active" href="#home">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
  <div class="topnav-right">
    <a href="#search">Search</a>
    <a href="#about">About</a>
  </div>
</div>

Step 2 - Add CSS:

/* Add black background color to the top navigation */
.topnav {
    background-color: #333;
    overflow: hidden;
}
/* Set the style for links in the navigation bar */
.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}
/* Change link color on hover */
.topnav a:hover {
  background-color: #ddd;
  color: black;
}
/* Add color for active/current link */
.topnav a.active {
  background-color: #04AA6D;
  color: white;
}
/* The right-aligned part within the top navigation */
.topnav-right {
  float: right;
}

Try It Yourself

Related Page

Tutorial:How to Create Responsive Top Navigation

Tutorial:CSS Navigation Bar