CSS Flexbox justify-content Property: How to Use space-between, space-around, and space-evenly for Horizontal Alignment
In modern web design, Flexbox has become one of the most powerful layout tools in CSS. The justify-content property plays a crucial role in aligning and distributing space between items within a container, especially in horizontal layouts. In this article, we'll explore how to use justify-content with various values like space-between, space-around, and space-evenly to achieve optimal alignment for your web designs.
Flexbox CSS justify-content: space-*
Flexbox layout and its properties are a set of properties which helps to align flex-items in a container. As we have discussed in detail in our previous articles:
- Flexbox is a set of properties.
- It helps to align grid elements in a container in many ways.
- It also helps to realign the way elements are arranged on mobile or responsive screens without writing too much code.
What is justify-content in CSS Flexbox?
The justify-content property in CSS Flexbox is used to align flex items along the main axis (horizontally by default) of a flex container. This property helps to distribute space between items, and is crucial when you want to create responsive and visually appealing layouts.
Justify-content is a property provided by the Flexbox concept, which works like the text-align property in CSS.
Justify-content values:
justify-content: center | flex-start | flex-end | space-around | space-between | space-evenly
justify-content: space-*
The justify-content: space-* helps to align flex-items horizontally within the flex-container. In other words, it deals with the horizontal alignment inside the container.
justify-content: space-around
space-around helps us to align items in such a way that items have equal space around them. The space between the items and the flex-container will be 1x, whereas space-between any two flex-items will be 2x.
Example
Example with number of flex-items changed
justify-content: space-evenly
space-evenly helps us to align items in such a way that items have even space between them. The flex-items will have 1x space between any two flex-items and the flex-items and flex-container edges.

Another example showing justify-content:space-evenly
Do you know
Recently, space-evenly has been made support and compatible with all modern browsers.
justify-content:space-between
space-between aligns the flex-items within the flex-container in such a way that space is allotted in between flex-items and not between the edges of the flex-container and the flex-items in the edges. The items in the edges move towards the edges in the left and right side respectively making space in between the flex items.
Example for justify-content:space-between
Flex box also provides way to order the flex-items by giving a numeric value thereby aligning elements in responsive using flexbox very easy.
Mastering the justify-content property in CSS Flexbox can significantly improve the layout and user experience of your website. Now that you've learned how each value affects the alignment of flex items, try experimenting with these properties in your own projects. Have any questions or want to share your own Flexbox experiences? Drop a comment below, and we’d love to discuss them!
Comments
Post a Comment