Centering without Known Dimensions

suggest change

Grid centers content without fixed dimensions or extra wrappers:

<div class="container">
  <div class="content">You can put anything here.</div>
</div>
.container {
  min-block-size: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.content {
  max-inline-size: 40rem;
  padding: 1.5rem;
}

If the content grows taller than the viewport, min-block-size lets the container expand instead of clipping it. place-items centers the grid item on both axes.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents