CHAPTER 32

CSS Navigation Bar

Learn how to create and style a professional website navigation bar using CSS.

01. What is CSS Navigation Bar?

A navigation bar helps users move between important pages of a website.
CSS can control navigation colors, spacing, alignment and hover effects.
Flexbox is commonly used to create modern navigation layouts.

02. Syntax

.navbar { display: flex; align-items: center; justify-content: space-between; } .navbar a { text-decoration: none; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>

<style>

.navbar {

    display: flex;

    align-items: center;

    justify-content: space-between;

    padding: 15px 25px;

    background: #020617;

}

.logo {

    color: #38bdf8;

    font-size: 22px;

    font-weight: bold;

}

.menu {

    display: flex;

    gap: 20px;

}

.menu a {

    color: white;

    text-decoration: none;

}

.menu a:hover {

    color: #38bdf8;

}

</style>

</head>

<body>

<nav class="navbar">

    <div class="logo">
        AIFA
    </div>

    <div class="menu">

        <a href="#">Home</a>

        <a href="#">Courses</a>

        <a href="#">About</a>

        <a href="#">Contact</a>

    </div>

</nav>

</body>
</html>

04. Important Points

✓ Flexbox is useful for aligning navigation items.
✓ Navigation links should have clear hover and focus states.
✓ Navigation should work properly on mobile screens.
✓ Use semantic HTML such as nav for navigation.

05. Common Mistakes

⚠ Creating navigation that overflows on mobile.
⚠ Using very small links.
⚠ Poor contrast between navigation text and background.
⚠ Ignoring keyboard accessibility.

06. Real World Use

Navigation bars are used on almost every professional website, including education portals, business websites and dashboards.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create an AIFA Navigation Bar

Create a navigation bar containing AIFA logo text and Home, Courses, About and Contact links.