DevPath · Learn to code ESPTEN

CSS: styling

Layout with Flexbox

Flexbox

Tired of fighting to center things? Flexbox is the modern way to align and distribute elements without the pain. It is activated by setting display: flex on the container (not on the children); from there, its children are placed in a row.

.container {
  display: flex;
  justify-content: center;  /* horizontal alignment */
  align-items: center;      /* vertical alignment */
  gap: 12px;                /* spacing between children */
}

With these few properties you solve most layouts. Seriously: mastering flexbox is the day you stop wrestling with CSS.

Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
← Colors, text and the box modelView the module →