Skip to main content

CSS justify-content Property

Along the main axis (horizontally), flex items are positioned by justify-content.

You can give it any one of these values:

  • center
  • flex-start (default)
  • flex-end
  • space-around
  • space-between
  • space-evenly

Center

With center, the flex items gather in the middle of the container.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: center to align them in the center of the container. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page

Flex-start

You get flex-start without setting anything, since it is the default: the flex items line up from the beginning of the container.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: flex-start to align them at the beginning of the container. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page

Flex-end

Using flex-end pushes the flex items to the far end of the container.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: flex-end to align them at the end of the container. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page

Space-around

In space-around, each flex item has space before and after it, and therefore between its neighbors too.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: space-around to display them with equal space around each item. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page

Space-between

With space-between, the first item sits at the start, the last at the end, and the remaining space goes between the items.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: space-between to display them with equal space between the items. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page

Space-evenly

Under space-evenly, the gaps around and between the flex items are all equal.

Prompt
Create a flex container with three numbered items (1, 2, 3) and use justify-content: space-evenly to display them with equal space around and between each item. Style the container with a light gray background and the items with a distinct background color and some padding.
Output: complete HTML page