How to create: Pill-shaped navigation

Learn how to use CSS to create a pill-shaped navigation menu.

Pill-shaped navigation

Try It Yourself

Create a pill-shaped navigation

Step 1 - Add HTML:

<div class="pill-nav">
  <a class="active" href="#home">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
  <a href="#about">About</a>
</div>

Step 2 - Add CSS:

/* Set link styles within the pill navigation menu */
.pill-nav a {
  display: inline-block;
  color: black;
  text-align: center;
  padding: 14px;
  text-decoration: none;
  font-size: 17px;
  border-radius: 5px;
}
/* Change link color on hover */
.pill-nav a:hover {
  background-color: #ddd;
  color: black;
}
/* Add color for active/current link */
.pill-nav a.active {
  background-color: dodgerblue;
  color: white;
}

Try It Yourself

Vertical pill-shaped navigation

Add display: block to the links, and they will be displayed vertically instead of horizontally:

Try It Yourself

Related Pages

Tutorial:CSS Navigation Bar

Tutorial:How to Create Top Navigation Bar