Flexbox centering

CSS, Layout · Dec 30, 2020

Horizontally and vertically centers a child element within a parent element using flexbox.

  • Use display: flex to create a flexbox layout.
  • Use justify-content: center to center the child horizontally.
  • Use align-items: center to center the child vertically.
<div class="flexbox-centering">
  <div>Centered content.</div>
</div>
.flexbox-centering {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
}

More like this

  • CSS Centering

    A collection of techniques for centering HTML elements in any situation using CSS.

    Collection · 5 snippets

  • Grid centering

    Horizontally and vertically centers a child element within a parent element using grid.

    CSS, Layout · Dec 30, 2020

  • Display table centering

    Vertically and horizontally centers a child element within its parent element, using display: table.

    CSS, Layout · Dec 30, 2020

  • Transform centering

    Vertically and horizontally centers a child element within its parent element using CSS transforms.

    CSS, Layout · Dec 30, 2020