The Fundamentals of CSS Alignment

September 15, 2025

Diagram of a CSS flex container with five labeled flex items arranged in two flex lines, showing how items wrap and are distributed within the container; annotated to identify the flex container, flex lines with striped background, and individual flex items.

While centering elements in CSS has become easy over time, there is still a lot of confusion around alignment in general. Let’s be honest, you always end up trying different combinations until it works, but you don’t really understand how it works, right?

Which property is for vertical alignment? align-content or align-items? Where should I add display: flex? Let’s add it everywhere! A height? Why do I need to define a height!? Maybe I should try with display: grid?

It’s time to clear all the confusion! Through this exploration, you will understand the logic behind all the alignment properties and how they work in each layout. It’s not another article about centering, we are going beyond!

Source: The Fundamentals of CSS Alignment

I’m going to admit it, I still find myself either looking up CSS Tricks’ great Flex cheat sheets or using my browser’s dev tools to remember which particular property and value will achieve my desired flex layout.

But this article lays it all out in clinical detail.