What is justify-content?

QuestionsQuestions8 SkillsProCSS Layout BasicsNov, 18 2025
0116

The justify-content property in CSS is used within a flex container to align and distribute space among its flex items along the main axis (the direction in which the flex items are laid out). It helps control how the extra space is distributed when the items do not fill the container.

Here are the common values for justify-content:

  1. flex-start: Aligns items to the start of the flex container (default).
  2. flex-end: Aligns items to the end of the flex container.
  3. center: Centers items within the flex container.
  4. space-between: Distributes items evenly, with the first item at the start and the last item at the end, leaving equal space between the items.
  5. space-around: Distributes items evenly, with equal space around them. The space before the first item and after the last item is half the space between items.
  6. space-evenly: Distributes items evenly, with equal space between all items, including before the first and after the last item.

Here’s an example of how to use justify-content in CSS:

.flex-container {
    display: flex;
    justify-content: space-between; /* Change this value to flex-start, flex-end, center, space-around, or space-evenly as needed */
}

In this example, the flex items within the .flex-container will be distributed with equal space between them due to the justify-content: space-between; property.

0 Comments

no data
Be the first to share your comment!