How do I center a div horizontally and vertically using Tailwind?
Asked on Oct 12, 2025
Answer
To center a div both horizontally and vertically using Tailwind CSS, you can use the flexbox utilities. By setting the parent container to "flex" and using "justify-center" and "items-center", you can achieve perfect centering.
<!-- 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:
- The "flex" class on the parent div enables flexbox layout.
- "justify-center" centers the content horizontally.
- "items-center" centers the content vertically.
- "h-screen" ensures the parent div takes the full height of the viewport.
Recommended Links: