0PricingLogin
Tailwind CSS Academy · Lesson

Justify Content and Align Items

Position children along the main axis with justify-* and cross axis with items-* to achieve common layout patterns.

Two Axes of Flex Alignment

Flexbox alignment operates on two perpendicular axes. The main axis runs in the direction of flex-row (horizontal) or flex-col (vertical). The cross axis is perpendicular to the main axis. justify-* controls alignment along the main axis. items-* controls alignment along the cross axis. Understanding this distinction is the key to mastering flex layout.

justify-content: Main Axis Positioning

The justify-* utilities correspond to CSS justify-content. In a flex row, they control horizontal positioning of the group of items. justify-start packs items to the left (default). justify-end packs to the right. justify-center centers the group. justify-between distributes items with equal space between them. justify-around adds equal space around each item. justify-evenly distributes space evenly including the edges.

<div class="flex justify-start  gap-2 bg-gray-100 p-4 mb-2"><div class="bg-blue-400 p-3">A</div><div class="bg-blue-400 p-3">B</div></div>
<div class="flex justify-center gap-2 bg-gray-100 p-4 mb-2"><div class="bg-blue-400 p-3">A</div><div class="bg-blue-400 p-3">B</div></div>
<div class="flex justify-between bg-gray-100 p-4 mb-2"><div class="bg-blue-400 p-3">A</div><div class="bg-blue-400 p-3">B</div></div>
<div class="flex justify-end   gap-2 bg-gray-100 p-4"><div class="bg-blue-400 p-3">A</div><div class="bg-blue-400 p-3">B</div></div>

All lessons in this course

  1. Enabling Flex and Direction
  2. Justify Content and Align Items
  3. Flex Grow, Shrink, and Basis
  4. Wrapping and Gap
← Back to Tailwind CSS Academy