HTML & CSS · Flexbox · Lesson 13 of 25
Building a Navbar with Flexbox
Concept
Building a Navbar with Flexbox
A classic use case is a logo on the left and nav links on the right, all aligned with one flex container.
This single pattern — display: flex plus justify-content: space-between — covers a huge share of real navbars, toolbars, and header layouts you'll build.
By the end of this lesson
- Explain the core idea behind Building a Navbar with Flexbox.
- Predict output before running a change.
- Test one realistic and one unusual input.
- Use the result to make the next decision.
How to study this page
- 1. Read one concept.
- 2. Change the example.
- 3. Run, compare, and explain.
- 4. Complete the challenge below.
Syntax
.nav {
display: flex;
justify-content: space-between;
align-items: center;
}ExampleRunnable
<nav class="nav">
<span>Logo</span>
<div class="links">Home About Contact</div>
</nav>
.nav {
display: flex;
justify-content: space-between;
align-items: center;
}Try it Yourself »Spacing the nav links themselves
.links {
display: flex;
gap: 20px;
}Self-check before continuing
Without looking at the example, describe what changes when you modify one input in Building a Navbar with Flexbox. Then reopen the editor and prove your explanation with a small test.
You are ready to continue when you can predict, test, and explain the result.
Your turn
Build a simple navbar with a logo on the left and three links on the right.
Loading editor…
Console