What are justify-content and align-items in CSS Flexbox?

Key takeaways:

  • The justify-content and align-items properties simplify alignment and spacing in CSS Flexbox layouts, making web designs responsive and adaptable.

  • justify-content property aligns items horizontally along the main axis, while the align-items property is used to align items vertically along the cross axis.

  • These properties are ideal for centering navigation bars, aligning content in banners, and creating visually balanced grid layouts.

Flexbox is a layout module designed to create flexible and responsive web designs. Two main properties of Flexbox are justify-content and align-items. This Answer discusses these properties, how they work, and how to effectively use them to create responsive and well-aligned web layouts.

justify-content in CSS Flexbox

The justify-content property controls the alignment of flex items along the main axis within a flex container. The main axis itself is set by the flex-direction property, which by default, arranges items in a horizontal row. This property is especially useful for adjusting the spacing between items.

Let’s see the common values for justify-content property:

  • flex-start: This is the default value that aligns items at the start of the container.

  • flex-end: This makes items sit at the end of the main axis.

  • center: This makes the flex items sit at the center of the main axis.

  • space-between: This distributes the remaining space between the flex items.

  • space-around: This distributes the remaining space around the flex items.

  • space-evenly: This distributes equal space between and around items.

Practical example of CSS justify-content property

Let's look at an example of using the justify-content property with different values:

Practice using the justify-content property by trying out this project, Build a Custom Form Maker with MERN Stack, where we create a full stack image sharing application focusing on styling the application.

align-items in CSS Flexbox

The align-items property controls the alignment of flex items along the cross axis(vertically by default). It is crucial for vertically aligning items when the main axis is horizontal or aligning horizontally in vertical layouts.

Let’s see the common values for align-items property:

  • flex-start: This aligns the flex items at the start of the cross axis, and aligns them vertically by default.

  • flex-end: This aligns the flex items at the end of the cross axis.

  • center: This aligns the flex items at the center of the cross axis, and centers them vertically by default.

  • stretch: This stretches flex items to fill the parent in the direction of the cross axis. This is a default value.

  • baseline: This aligns the flex items at the baseline of the cross axis.

Practical example of CSS align-items property

Let's look at an example of using the align-items property with different values:

Want to get hands-on practice with using align-items in a real-world application? Try out this project, Build a Microblogging App Using PHP, HTML, JavaScript, and CSS, where we create a microblogging platform with search and admin features.

Understanding justify-content and align-items is essential to mastering CSS Flexbox and creating dynamic, responsive web layouts. By effectively utilizing these properties, you can control the alignment and distribution of flex items, leading to cleaner and more adaptable designs.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


What is the difference between justify-content and align-items?

justify-content aligns items along the main axis, while align-items aligns them perpendicularly along the cross axis.


Can I use justify-content and align-items together?

Yes, combining these properties allows for precise alignment and distribution of flex items both horizontally and vertically within a container.


How do I align a single item in Flexbox?

Use the align-self property for individual item alignment.


Free Resources