Links & Menus

Style links, hover states, active states, and navigation layouts.

Links are one of the most important parts of the web. They allow users to move from one page to another, visit external websites, download files, and access different sections of a website. Navigation menus are collections of links that help visitors find information quickly and easily.

By default, links have a basic browser style, usually blue and underlined. CSS allows developers to customize links and navigation menus to match the design of a website and improve the user experience.

Why Style Links and Navigation Menus?

Well-designed links and menus help:

  • Improve website navigation
  • Enhance user experience
  • Create a professional appearance
  • Highlight important pages
  • Make websites easier to use

For example, an online store may have a navigation menu with links to products, categories, offers, and customer support pages.

Styling Basic Links

HTML links are created using the anchor element.

Example

html
<a href="#">Visit Our Blog</a>

CSS can change the appearance of links.

Example

css
a {
  color: blue;
  text-decoration: none;
}

In this example:

  • The link text becomes blue.
  • The default underline is removed.

Link States

Links can have different styles depending on how users interact with them.

Unvisited Link

css
a:link {
  color: blue;
}

Styles links that have not been visited.

Visited Link

css
a:visited {
  color: purple;
}

Styles links that users have already clicked.

Hover Effect

css
a:hover {
  color: red;
}

Changes the link color when the user moves the mouse over it.

Active Link

css
a:active {
  color: green;
}

Applies styling while the link is being clicked.

These states help provide visual feedback to users.

Creating a Simple Navigation Menu

Navigation menus are often built using unordered lists.

HTML

html
<ul class="menu">
  <li><a href="#">Home</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Services</a></li>
  <li><a href="#">Contact</a></li>
</ul>

CSS

css
.menu {
  list-style: none;
  display: flex;
  gap: 20px;
}

.menu a {
  text-decoration: none;
  color: black;
}

This creates a simple horizontal navigation menu.

Adding Hover Effects to Menus

Hover effects make menus more interactive.

Example

css
.menu a:hover {
  color: blue;
}

When users move their mouse over a menu item, the color changes to blue.

Creating Button-Like Links

Links can also be styled as buttons.

Example

css
.button {
  background-color: blue;
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 5px;
}

This is commonly used for Sign Up and Learn More buttons.

Real-World Example

Imagine a travel website:

  • The navigation menu contains links to destinations, tours, and contact pages.
  • Hover effects highlight menu items.
  • Call-to-action links are styled as buttons.
  • Visited links help users track pages they have already viewed.

These design choices improve navigation and make the website easier to use.

Conclusion

CSS links and navigation menus are essential for creating user-friendly websites. By styling links, using link states, and building attractive navigation menus, developers can improve both appearance and usability. Learning how to customize links and menus is an important step toward building professional and engaging websites.

Let's learn with DevBrainBox AI