What You'll Learn
You'll discover how justify-content: space-evenly creates perfectly equal spacing in flex containers, and learn about "safe" alignment to prevent content from being cut off.
space-evenly: Perfect Distribution
You've already seen spacing options like flex-start, center, and space-between. Now meet space-evenly—the most balanced distribution option.
The Analogy: Imagine placing picture frames on a wall. With space-evenly, the space before the first frame, between all frames, and after the last frame is exactly the same. Every gap is identical.
.container {
display: flex;
justify-content: space-evenly;
}
This creates equal space on both ends and between all flex items. Unlike space-around (which gives half-space at the edges), space-evenly treats edges and gaps identically.
Safe Centering: Preventing Overflow
Sometimes centered content can overflow its container and get cut off—especially on small screens. This is where "safe" alignment comes in.
The problem: When you use justify-content: center and content is wider than the container, the overflowing edges become unreachable (scrolling won't help because they overflow equally on both sides).
The solution: Use safe center as a value:
.container {
display: flex;
justify-content: safe center;
}
With safe, if the content would overflow when centered, the browser automatically switches to flex-start alignment instead. Your content stays accessible and scrollable.
When to Use Each
space-evenly: Navigation bars, galleries, or any layout where perfect visual balance matterssafe center: Modal dialogs, cards, or any centered content that might overflow on small screens
Key Takeaway: justify-content: space-evenly gives truly equal spacing everywhere, while safe alignment modes protect against content getting cut off when centered items overflow their container.