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

Align Content


This property is used to align the lines of a flex container when there is extra space in the cross-axis. It only has an effect on multi-line flex containers (when flex-wrap is wrap or wrap-reverse) and has no effect on single-line containers.

Example 1: Aligning Lines to the Start

HTML

<div class="flex-container content-start">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

.flex-container {
  display: flex;
  flex-wrap: wrap; /* Must be a multi-line container. */
  height: 200px; /* Must have extra space in the cross-axis. */
  border: 2px solid #000;
}

.content-start {
  align-content: flex-start; /* Packs lines to the start of the container. */
}

Explanation

align-content: flex-start packs all the lines of flex items toward the start of the cross axis (the top of the container).


Example 2: Aligning Lines to the Center

HTML

<div class="flex-container content-center">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

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

.content-center {
  align-content: center; /* Packs lines to the center of the container. */
}

Explanation

align-content: center groups all the lines and centers them vertically within the flex container, with equal space above and below the group.


Example 3: Aligning Lines to the End

HTML

<div class="flex-container content-end">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

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

.content-end {
  align-content: flex-end; /* Packs lines to the end of the container. */
}

Explanation

align-content: flex-end packs all the lines of flex items toward the end of the cross axis (the bottom of the container).


Example 4: Distributing Lines with Space Between

HTML

<div class="flex-container content-between">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

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

.content-between {
  align-content: space-between; /* Distributes lines with space between them. */
}

Explanation

align-content: space-between takes all the extra vertical space and distributes it evenly between the lines of flex items.


Example 5: Distributing Lines with Space Around

HTML

<div class="flex-container content-around">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

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

.content-around {
  align-content: space-around; /* Distributes space around each line. */
}

Explanation

align-content: space-around distributes the space such that each line has equal space above and below it.


Example 6: Stretching Lines to Fill Space

HTML

<div class="flex-container content-stretch">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

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

.content-stretch {
  align-content: stretch; /* Stretches the lines to take up remaining space (default). */
}

Explanation

align-content: stretch is the default value. It causes the lines themselves to stretch and consume any extra space in the cross axis.


Example 7: Align Content vs. Align Items

HTML

<div class="flex-container align-items-demo">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
</div>

<div class="flex-container align-content-demo">
  <div class="item">1</div> <div class="item">2</div> <div class="item">3</div>
  <div class="item">4</div> <div class="item">5</div>
</div>

CSS

.align-items-demo {
  align-items: center; /* `align-items` works on a single line. */
  height: 150px;
  border: 2px solid #f0ad4e;
}

.align-content-demo {
  flex-wrap: wrap;
  align-content: center; /* `align-content` works on multiple lines. */
  height: 250px;
  border: 2px solid #5bc0de;
}

Explanation

This example highlights the difference: align-items aligns items within a line, while align-content aligns the lines themselves within the container. The first container centers the single line of items; the second container centers the two lines of items as a block.