Skip to main content
๐ŸŽจ CSS Basics

Centering with flexbox ๐ŸŽฏ

Centering something perfectly in the middle used to be tricky. Flexbox makes it easy with three steps. We'll add them one line at a time โ€” tap the hint to reveal each step.

.container {
  display: flex;            /* step 1: turn on flexbox */
  justify-content: center;  /* step 2: center left-to-right */
  align-items: center;      /* step 3: center top-to-bottom */
}

Three short lines, each one the same property: value; shape you already know:

  1. display: flex; turns the box into a flex container.
  2. justify-content: center; centers the children horizontally.
  3. align-items: center; centers the children vertically.

Your task

Make .container a flexbox that centers its content both ways. Drag the blocks in order, or tap the hint to fill it in one step at a time.

โšก 40 XP

Hints

index.htmliframe
Loading editorโ€ฆ
Preview
Run your code to see test results.