Centering Content of Unknown Size

suggest change

Grid centers content without knowing either element's dimensions:

.container {
  min-block-size: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.content {
  inline-size: min(100%, 40rem);
}

100dvh follows the dynamic viewport height, which is useful when mobile browser controls expand or collapse. The padding prevents the content from touching the viewport edge, while min-block-size allows the container to grow when its content is taller than the viewport.

Use 100vh as a deliberate fallback only when the target browser policy requires it:

.container {
  min-block-size: 100vh;
  min-block-size: 100dvh;
}

Feedback about page:

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



Table Of Contents