bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Modern Layout
CSS•Modern Layout

CSS Grid Container - Align Grid Content

Inside the grid container you can define the alignment of the grid content with the following properties:

  • justify-content - Aligns the grid content when it does not use all available space on the main-axis (horizontally)
  • align-content - Aligns the grid content when it does not use all available space on the cross-axis (vertically)
  • place-content - Shorthand property for align-content and justify-content

The CSS justify-content Property

The justify-content property is used to align the grid content when it does not use all available space on the main-axis (horizontally).

This property can have one of the following values:

  • space-evenly
  • space-around
  • space-between
  • center
  • start
  • end

Note

The grid content's total width has to be less than the container's width for the justify-content property to have any effect.

space-evenly
space-around
space-between
center
start
end

The CSS align-content Property

The align-content property is used to align the grid content when it does not use all available space on the cross-axis (vertically).

This property can have one of the following values:

  • space-evenly
  • space-around
  • space-between
  • center
  • start
  • end

Note

The grid content's total height has to be less than the container's height for the align-content property to have any effect.

In the following examples we use a 300 pixels high container, to better demonstrate the align-content property.

center
space-evenly
space-around
space-between
start
end

The CSS place-content Property

The place-content property is a shorthand property for the align-content and the justify-content properties.

If place-content has two values

  • place-content: start center; - the align-content value is 'start' and justify-content value is 'center'

If place-content has one value

  • place-content: end; - both align-content and justify-content values are 'end'

Note

The grid item's total height and width has to be less than the container's height and width for the place-content property to have any effect.

center
end space-between

Previous

CSS Flex Items

Next

Responsive Web Design - Images

This chapter

Overview
24

Lessons

64m

Read time

1. CSS Flexbox2. CSS Grid Layout3. Responsive Web Design4. CSS Flex Container5. CSS Grid Container6. Responsive Web Design - The Viewport7. CSS Flexbox justify-content8. CSS Grid Tracks9. Responsive Web Design - Building a Grid View10. CSS Flexbox Align11. CSS Grid Gap12. Responsive Web Design - Media Queries13. CSS Flex Items14. CSS Grid Container - Align Grid Content15. Responsive Web Design - Images16. CSS Responsive Flexbox17. CSS Grid Items18. Responsive Web Design - Frameworks19. CSS Naming Grid Items20. Responsive Web Design - Templates21. CSS Grid Items - Alignment22. CSS Grid Items - Order23. CSS 12-Column Grid Layout24. CSS @supports Rule

On this page

The CSS justify-content PropertyThe CSS align-content PropertyThe CSS place-content Property