justify-content: Main Axis Alignment
You'll learn how to distribute extra space between and around flex items along the main axis.
When you create a flex container, you often have leftover space along the main axis (the direction items flow). The justify-content property controls how that extra space gets distributed among your flex items.
How It Works
Think of justify-content like arranging books on a shelf. You've got five books, but the shelf is ten feet long—where do the books go? At the left? Centered? Evenly spaced?
justify-content answers that question for your flex items:
Common Values
flex-start (default) — Items pack at the start of the main axis, leaving extra space at the end.
flex-end — Items pack at the end, leaving space at the start.
center — Items cluster in the middle, with equal space on both sides.
space-between — Items spread out with maximum space between them; first item touches the start, last item touches the end, no space on the edges.
space-around — Items get equal space around them (think of each item having invisible padding); edges get half-space.
space-evenly — All gaps are equal—between items and at the edges.
The Main Axis Connection
Remember: justify-content works along the main axis. If flex-direction is row, you're distributing horizontal space. If it's column, you're distributing vertical space. The property name stays the same; the direction changes based on your flex direction.
Key Takeaway: justify-content controls how extra space is distributed along the main axis, letting you align flex items at the start, end, center, or spread them evenly with space-between, space-around, or space-evenly.