Styling ComponentsExtra· 40 min read

Links & Navigation Bars

Style links and turn a plain list into a professional navigation bar — a skill every site needs.

What you will learn

  • Style links and their states
  • Build a horizontal navbar from a list
  • Add hover effects

Link states

Links have states you can style with pseudo-classes: :hover (mouse over), :active (being clicked), :visited (already visited).

A hover state
<style>
  a.btn { color:#4338ca; text-decoration:none; font-weight:600; }
  a.btn:hover { color:#06b6d4; text-decoration:underline; }
</style>
<a class="btn" href="#">Hover over me</a>
Live preview

There are two rules for the same link. The first, a.btn, is the normal look: indigo, no underline, semi-bold. The second, a.btn:hover, only applies while the mouse is over the link — it switches the colour to cyan and brings the underline back. The :hover part is a pseudo-class: a condition CSS watches for. Move your mouse on and off the link to see it toggle.

A horizontal navbar from a list

Here is the trick behind almost every navigation bar on the web: start with a plain bullet list of links, then use CSS to strip the bullets and lay the items in a row. The code below turns an everyday <ul> into a polished navbar — read it first, then follow the numbered steps under it.

A real navigation bar
<style>
  .nav { list-style: none; margin: 0; padding: 0; display: flex; background: #4338ca; border-radius: 10px; }
  .nav li a {
    display: block; color: #fff; text-decoration: none;
    padding: 14px 20px; transition: background .2s;
  }
  .nav li a:hover { background: #3730a3; }
</style>
<ul class="nav">
  <li><a href="#">Home</a></li>
  <li><a href="#">Courses</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Contact</a></li>
</ul>
Live preview

That professional navbar is just a plain <ul> list transformed by CSS. Here is each step of the transformation, in order:

  1. Start with an ordinary <ul> of <li> items, each holding a link — the same list you learned in HTML.
  2. On the .nav list, list-style: none removes the bullet dots, and margin: 0; padding: 0 strips the default indent.
  3. display: flex on the .nav lays the list items in a horizontal row instead of stacking them vertically.
  4. On the links, display: block plus padding: 14px 20px makes the whole padded area clickable (not just the text), and text-decoration: none removes underlines.
  5. .nav li a:hover darkens the background on hover, and transition makes that colour change fade smoothly instead of snapping.

Tip: The recipe: take a <ul>, remove bullets with list-style: none, zero its margin/padding, and set display: flex to lay the items in a row. That is a navbar.

Q. Which pseudo-class styles a link when the mouse is over it?

Answer: :hover applies while the pointer is over the element. :active is during the click; :visited is for visited links.

✍️ Practice

  1. Style a link to remove the underline and change colour on hover.
  2. Build a horizontal navbar from a <ul> with hover backgrounds.

🏠 Homework

  1. Add a styled navigation bar to the top of your landing page.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →