Ask any question about Tailwind CSS here... and get an instant response.
How do I center a div horizontally and vertically using Tailwind utilities?
Asked on Nov 18, 2025
Answer
To center a div both horizontally and vertically using Tailwind CSS, you can utilize flexbox utilities. By setting the parent container to "flex" and using "justify-center" and "items-center", you can align the child div in the center.
<!-- BEGIN COPY / PASTE -->
<div class="flex justify-center items-center h-screen">
<div class="bg-blue-500 text-white p-4">
Centered Content
</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- "flex" makes the parent a flex container.
- "justify-center" centers the child horizontally.
- "items-center" centers the child vertically.
- "h-screen" ensures the parent takes full viewport height, which is helpful for full-page centering.
Recommended Links:
