Justify Items
Controls alignment of grid items along their inline (row) axis within their grid areas. While justify-content controls the alignment of the entire grid container's contents, justify-items controls individual grid items within their cells. This is particularly useful for grid layouts where you want consistent alignment of items within their allocated spaces.
Flexbox & Grid1 variant5 examples
Basic usage:
<div class="grid grid-cols-3 justify-items-start gap-4 bg-gray-100 p-4 rounded-lg">
<div class="bg-blue-100 p-4 rounded">Start aligned</div>
<div class="bg-blue-200 p-4 rounded">Start aligned</div>
<div class="bg-blue-300 p-4 rounded">Start aligned</div>
<div class="bg-blue-100 p-4 rounded">Start aligned</div>
<div class="bg-blue-200 p-4 rounded">Start aligned</div>
<div class="bg-blue-300 p-4 rounded">Start aligned</div>
</div>
Examples
<div class="grid grid-cols-3 justify-items-start gap-4 bg-gray-100 p-4 rounded-lg">
<div class="bg-blue-100 p-4 rounded">Start aligned</div>
<div class="bg-blue-200 p-4 rounded">Start aligned</div>
<div class="bg-blue-300 p-4 rounded">Start aligned</div>
<div class="bg-blue-100 p-4 rounded">Start aligned</div>
<div class="bg-blue-200 p-4 rounded">Start aligned</div>
<div class="bg-blue-300 p-4 rounded">Start aligned</div>
</div>
<div class="grid grid-cols-3 justify-items-center gap-4 bg-gray-100 p-4 rounded-lg">
<div class="bg-green-100 p-4 rounded">Centered</div>
<div class="bg-green-200 p-4 rounded">Centered</div>
<div class="bg-green-300 p-4 rounded">Centered</div>
<div class="bg-green-100 p-4 rounded">Centered</div>
<div class="bg-green-200 p-4 rounded">Centered</div>
<div class="bg-green-300 p-4 rounded">Centered</div>
</div>
<div class="grid grid-cols-3 justify-items-end gap-4 bg-gray-100 p-4 rounded-lg">
<div class="bg-purple-100 p-4 rounded">End aligned</div>
<div class="bg-purple-200 p-4 rounded">End aligned</div>
<div class="bg-purple-300 p-4 rounded">End aligned</div>
<div class="bg-purple-100 p-4 rounded">End aligned</div>
<div class="bg-purple-200 p-4 rounded">End aligned</div>
<div class="bg-purple-300 p-4 rounded">End aligned</div>
</div>
<div class="grid grid-cols-3 justify-items-stretch gap-4 bg-gray-100 p-4 rounded-lg">
<div class="bg-blue-100 p-4 rounded">Stretched</div>
<div class="bg-blue-200 p-4 rounded">Stretched</div>
<div class="bg-blue-300 p-4 rounded">Stretched</div>
<div class="bg-blue-100 p-4 rounded">Stretched</div>
<div class="bg-blue-200 p-4 rounded">Stretched</div>
<div class="bg-blue-300 p-4 rounded">Stretched</div>
</div>
<!-- Card layout with centered content in each cell -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6 justify-items-center p-4 bg-gray-100 rounded-lg">
<div class="max-w-sm bg-white rounded-lg shadow-md overflow-hidden w-full">
<div class="h-40 bg-blue-200"></div>
<div class="p-4">
<h3 class="font-bold mb-2">Card Title 1</h3>
<p class="text-gray-600">Each card is centered in its grid cell but maintains its width.</p>
</div>
</div>
<div class="max-w-sm bg-white rounded-lg shadow-md overflow-hidden w-full">
<div class="h-40 bg-blue-300"></div>
<div class="p-4">
<h3 class="font-bold mb-2">Card Title 2</h3>
<p class="text-gray-600">Using justify-items-center creates a balanced, centered layout.</p>
</div>
</div>
<div class="max-w-sm bg-white rounded-lg shadow-md overflow-hidden w-full">
<div class="h-40 bg-blue-400"></div>
<div class="p-4">
<h3 class="font-bold mb-2">Card Title 3</h3>
<p class="text-gray-600">This works well for consistent width items in a grid.</p>
</div>
</div>
</div>
Live Preview
Try the Justify Items utility with different values
Variants
auto: uses align value from item's justify-self property or stretch if not set; start: items aligned to start of their grid area; end: items aligned to end of their grid area; center: items centered within their grid area; stretch: items stretched to fill their grid area horizontally
autostartendcenterstretch
Tips & Reference
Related Functions
Flex DirectionControls the direction in which flex items are placed in the...
Flex WrapControls whether flex items should wrap onto multiple lines ...
FlexSets how a flex item grows or shrinks to fit available space...
Flex GrowControls the ability of a flex item to grow when there is ex...
Flex ShrinkControls the ability of a flex item to shrink when there isn...
View all Flexbox & Grid utilities