</> Code Corner

CSS · CSS Tutorial · Lesson 32

CSS Navigation Bar

Build vertical and horizontal nav bars from lists.

A navigation bar is basically a list of links, so using <ul> and <li> elements makes perfect sense.

Example

<style>
ul.nav { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; display: flex; }
ul.nav li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; font-family: Arial; }
ul.nav li a:hover { background-color: #111; }
ul.nav li a.active { background-color: #04AA6D; }
</style>
<ul class="nav">
  <li><a class="active" href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>
  • Remove bullets with list-style-type: none
  • Make links fill the clickable area with display: block and padding
  • Lay items in a row with flexbox (or float/inline-block)

Keep reading “CSS Navigation Bar”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋