Place items alignment helps you center or position items inside a container easily. It controls how items line up horizontally and vertically together.
Place items alignment in Tailwind
place-items-{value}
// where {value} can be:
// start, center, end, stretchThis class works on containers with display: grid or display: inline-grid.
It sets both align-items and justify-items at the same time.
<div class="grid place-items-center">
<div>Centered Item</div>
</div><div class="grid place-items-start">
<div>Top Left Item</div>
</div><div class="grid place-items-end">
<div>Bottom Right Item</div>
</div><div class="grid place-items-stretch">
<div>Stretched Item</div>
</div>This example shows a square box with a blue item perfectly centered inside using place-items-center. The container uses grid layout and the item is horizontally and vertically centered.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Place Items Alignment Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-100 p-6"> <section class="grid place-items-center h-48 w-48 bg-white border border-gray-300 mx-auto"> <div class="bg-blue-500 text-white px-4 py-2 rounded">Centered</div> </section> </body> </html>
Use place-items only on grid containers, not flex containers.
It combines align-items and justify-items for quick alignment.
For flexbox, use items- and justify- classes separately.
Place items alignment controls horizontal and vertical alignment of items inside a grid container.
Use place-items-center to center items both ways easily.
It simplifies layout by combining two alignment properties into one class.
Practice
place-items-center do inside a grid container?Solution
Step 1: Understand place-items property
Theplace-itemsproperty in Tailwind combinesalign-items(vertical) andjustify-items(horizontal) alignment.Step 2: Effect of place-items-center
The classplace-items-centercenters items both horizontally and vertically inside the grid container.Final Answer:
Centers items both horizontally and vertically -> Option AQuick Check:
place-items-center = center both ways [OK]
- Thinking it only centers horizontally or vertically
- Confusing place-items with place-content
- Assuming it affects flexbox instead of grid
Solution
Step 1: Understand place-items syntax
Theplace-itemsclass uses one keyword to set both horizontal and vertical alignment equally, likeplace-items-centerorplace-items-start.Step 2: Aligning differently horizontally and vertically
To align differently, Tailwind uses separate classesjustify-items-*for horizontal anditems-*for vertical.place-items-startaligns both horizontally and vertically to start.Final Answer:
place-items-start -> Option AQuick Check:
place-items-start aligns both ways to start [OK]
- Trying to combine two directions in one place-items class
- Using non-existent classes like place-items-start-center
- Confusing place-items with justify-items or items classes
<div class="grid grid-cols-2 h-40 place-items-center bg-gray-100"> <div class="bg-blue-500 w-10 h-10">A</div> <div class="bg-red-500 w-10 h-10">B</div> </div>
Where will the blue and red boxes appear inside the grid cells?
Solution
Step 1: Analyze the grid container classes
The container usesgrid-cols-2for two columns,h-40for height, andplace-items-centerwhich centers items horizontally and vertically.Step 2: Effect on child divs
Each child box (blue and red) will be placed in their grid cell and centered both horizontally and vertically because ofplace-items-center.Final Answer:
Both boxes centered horizontally and vertically in their cells -> Option DQuick Check:
place-items-center centers items in grid cells [OK]
- Assuming items stretch by default
- Thinking place-items-center aligns only vertically
- Ignoring grid cell boundaries
place-items-center and items are stuck at the top-left. What is the likely mistake?Solution
Step 1: Check container display property
Theplace-items-centerclass works only if the container is a grid. Ifdisplay: gridis missing, alignment won't work.Step 2: Effect of missing grid display
Without grid, items behave like normal block elements and stay top-left by default, ignoring place-items classes.Final Answer:
The container is not set to display grid -> Option BQuick Check:
place-items-center needs grid display [OK]
- Forgetting to add grid display
- Confusing place-items with place-content
- Assuming fixed size of children affects alignment
Solution
Step 1: Identify required alignments
Bottom-right means horizontal end (right: justify-items-end) and vertical end (bottom: align-items-end / items-end).Step 2: Use place-items-end
Theplace-items-endclass sets bothjustify-itemsandalign-itemsto 'end', perfectly aligning items to bottom-right.Step 3: Check other options
place-items-bottom-rightdoes not exist.justify-items-end items-centercenters vertically.place-content-endaligns the whole grid content, not individual items.Final Answer:
grid grid-cols-3 place-items-end -> Option CQuick Check:
place-items-end = end both ways (bottom-right) [OK]
- Using non-existent place-items-bottom-right class
- Using justify-items-end items-center (centers vertically)
- Using place-content-end instead of place-items
Ready to prove it?
Pass the test and this pattern moves unknown
