CSS Questions & Answers Logo
CSS Questions & Answers Part of the Q&A Network
Q&A Logo

What’s the difference between justify-content and align-items in Flexbox?

Asked on Sep 05, 2025

Answer

In Flexbox, "justify-content" and "align-items" are used to control the alignment of flex items, but they operate on different axes. "Justify-content" aligns items along the main axis, while "align-items" aligns them along the cross axis.

Example Concept: In Flexbox, "justify-content" is used to align flex items along the container's main axis (horizontal by default), affecting how space is distributed between items. "Align-items" aligns items along the cross axis (vertical by default), affecting how items are positioned within the container's height. For example, "justify-content: center" centers items horizontally, while "align-items: center" centers them vertically.

Additional Comment:
  • The main axis is determined by the "flex-direction" property, which defaults to "row".
  • "Justify-content" options include "flex-start", "flex-end", "center", "space-between", "space-around", and "space-evenly".
  • "Align-items" options include "flex-start", "flex-end", "center", "baseline", and "stretch".
  • Understanding these properties helps in creating responsive and well-aligned layouts.
✅ Answered with CSS best practices.

← Back to All Questions
The Q&A Network