Course contentsShow
← Web Development
Lesson 301 of 2,9825. FlexboxFree lesson

Space-Between Groups

Create navigation with left and right groups using justify-content.

Space-Between Groups

You'll learn how to create navigation bars with items grouped on opposite sides using justify-content: space-between.

What It Means

In navigation bars, you often want some items clustered on the left (like a logo or home link) and others on the right (like login/signup buttons). The justify-content: space-between property creates maximum space between groups, pushing the first group to the start and the last group to the end of the flex container.

How It Works

When you apply justify-content: space-between to a flex container with multiple items:

  1. The first item (or group of consecutive items) sticks to the left edge
  2. The last item (or group) sticks to the right edge
  3. Any remaining space distributes evenly between groups

The key is structuring your HTML so items you want together are actually together in your markup. Think of it like organizing books on a shelf: place reference books on the far left, fiction on the far right, and the shelf automatically maximizes the space between these two sections.

Practical Navigation Example

nav {
  display: flex;
  justify-content: space-between;
}
<nav>
  <div class="left-group">
    <a href="/">Home</a>
    <a href="/about">About</a>
  </div>
  <div class="right-group">
    <a href="/login">Login</a>
    <a href="/signup">Sign Up</a>
  </div>
</nav>

The left group naturally clusters together on the left, the right group on the right, with maximum space between them.

Key Takeaway: Use justify-content: space-between with grouped flex items to automatically push navigation elements to opposite ends of a container.