How do I center align horizontally with flex column?

Eugene Yeboah

Written by:

Eugene Yeboah • April 21, 2023

How do I center align horizontally with flex column?

To center align horizontally with a flex column, follow the steps below:

  1. Create a parent container and set the display property to flex. Set the flex-direction to column.
  2. Set the justify-content property of the parent container to center. This will center align the child elements along the vertical axis.

Here's an example of how you can center align horizontally with a flex column layout in CSS:

HTML:

<div class="parent">
  <div class="child">
    <!-- Content of the child element goes here -->
  </div>
</div>

CSS:

.parent{
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.child{
  /* Styles for the child element go here */
}