CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Justify Content


This property is used to align flex items along the main axis of the flex container. It distributes any leftover free space when either all the flex items on a line are inflexible or are flexible but have reached their maximum size.

Example 1: Aligning to the Start

HTML

<div class="flex-container justify-start">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-start {
  justify-content: flex-start; /* Groups items at the start of the line (default). */
}

Explanation

justify-content: flex-start packs the items toward the start of the main axis (left side in a row, top in a column). This is the default behavior.


Example 2: Aligning to the Center

HTML

<div class="flex-container justify-center">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-center {
  justify-content: center; /* Centers the items along the main axis. */
}

Explanation

justify-content: center groups the flex items together at the center of the main axis, with equal space on either side of the group.


Example 3: Aligning to the End

HTML

<div class="flex-container justify-end">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-end {
  justify-content: flex-end; /* Groups items at the end of the line. */
}

Explanation

justify-content: flex-end packs the items toward the end of the main axis (right side in a row, bottom in a column).


Example 4: Distributing Space Between

HTML

<div class="flex-container justify-between">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-between {
  justify-content: space-between; /* Distributes space between the items. */
}

Explanation

justify-content: space-between distributes the extra space evenly between the flex items. The first item is on the start line, the last item is on the end line.


Example 5: Distributing Space Around

HTML

<div class="flex-container justify-around">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-around {
  justify-content: space-around; /* Distributes space around each item. */
}

Explanation

justify-content: space-around distributes space such that each item has equal space on both sides. This results in the space between any two items being double the space before the first and after the last item.


Example 6: Distributing Space Evenly

HTML

<div class="flex-container justify-evenly">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  border: 2px solid #000;
}

.justify-evenly {
  justify-content: space-evenly; /* Distributes space so the spacing between any two items is equal. */
}

Explanation

justify-content: space-evenly distributes the space so that the spacing between any two items, and the space to the container edges, is identical.


Example 7: Justify Content in a Column

HTML

<div class="flex-container column-justify">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

CSS

.flex-container {
  display: flex;
  flex-direction: column; /* The main axis is now vertical. */
  height: 300px;
  border: 2px solid #4CAF50;
}

.column-justify {
  justify-content: space-between; /* Distributes items along the vertical axis. */
}

Explanation

When flex-direction is column, justify-content works along the vertical axis. In this case, space-between places the first item at the top, the last at the bottom, and the second in the middle.