How to create: Navigation links with bottom border

Learn how to use CSS to create navigation links with bottom border (underline).

Navigation links with bottom border

Try it yourself

Create a navigation menu

Step 1 - Add HTML:

<div class="topnav">
  <a href="#home" class="active">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
</div>

Step 2 - Add CSS:

/* Add black background color to the top navigation */
.topnav {
  background-color: #333;
  overflow: hidden;
{}
/* Set the style of links in the navigation bar */
.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  border-bottom: 3px solid transparent;
{}
.topnav a:hover {
  border-bottom: 3px solid red;
{}
.topnav a.active {
  border-bottom: 3px solid red;
{}

Try it yourself

Related pages

Tutorial:How to Create Responsive Top Navigation

Tutorial:CSS Navigation Bar