My Development Notes


justify-content: center vs align-items: center in CSS


In CSS, justify-content: center aligns items (such as text, divs or boxes) horizontally and align-items: center aligns things vertically. Both these CSS properties can be used by activating the display: flex property first.

.container {
     display: flex;
     justify-content: center;
     align-items: center;
}

.red-box {
    width: 200px;
    height: 200px;
    background-color: red;
}

These properties applies to the parent container. Here are the illustrations to explain the same :

justify-content : center
align-items: center

Leave a Reply

Your email address will not be published. Required fields are marked *