Problem: The #1 CSS question: centering things.

Solution#

html
<div class="grid place-items-center min-h-screen">
  <div class="p-8 rounded-xl shadow-lg">Perfectly centered</div>
</div>

Why this works#

grid + place-items-center centers on both axes in one declaration pair; flex + m-auto is the alternative.

Variants#

  • Responsive: add screen prefixes to the core classes
  • Dark: pair each color utility with its dark: twin
  • Animated: add transition + a state variant for motion

cookbook/index|Cookbook index · utilities/index|Utilities reference · patterns/index|Layout patterns