Retour au cours

Lesson 53: Flex Container Property: justify-content (Main Axis)

**La Maîtrise de CSS : De zéro à expert en 100 leçons** *(Alternative, slightly punchier version using a common French idiomatic structure for full coverage: CSS : Maîtrisez l'essentiel en 100 leçons, but the first option is closer to the original progression.)*

53. Flex Container Property: justify-content (Main Axis)

justify-content controls how space is distributed between and around flex items along the main axis.

ValueDescription
flex-start (default)Items are packed toward the start of the flex direction.
flex-endItems are packed toward the end of the flex direction.
centerItems are centered along the main axis.
space-betweenItems are evenly distributed; the first item is flush with the start, the last item is flush with the end.
space-aroundItems are evenly distributed with equal space around them (leading to half-sized space at the ends).
space-evenlyItems and the spacing between them are distributed so that the space before the first item, between items, and after the last item is exactly the same.

Example: Horizontal Centering

css .container { display: flex; width: 500px; border: 1px solid red; }

/* Centers items horizontally (if flex-direction: row) */ .centered-row { justify-content: center; }

/* Pushes items to the edges with equal spacing between them */ .spaced-out { justify-content: space-between; }

Common Use: Centering navigation links or spacing elements equally in a footer.