Nearby lessons

6 of 15

๐Ÿ”ฒ CSS Grid Container

๐Ÿ“Œ What is a Grid Container?

The grid container is the parent element where the CSS Grid layout starts. ๐ŸŽฏ It defines the grid structure and controls how grid items (children) are placed.

Using display: grid or display: inline-grid turns any HTML element into a grid container.

This section covers each grid container property with clear examples so you can confidently build complex, responsive layouts using CSS Grid. ๐Ÿš€๐ŸŽจ

๐Ÿ“‹ What Can Grid Container Do?

  • ๐Ÿ“ฆ Create rows and columns with ease
  • ๐Ÿงฉ Place items in precise grid locations
  • โš™๏ธ Control spacing, alignment, and gaps

๐Ÿ”ธ justify-content Property

AttributeValueDescription
justify-contentspace-evenlyEqual space around and between items
justify-contentspace-aroundEqual space around items (half-size on ends)
justify-contentspace-betweenEqual space between items (no space on ends)
justify-contentcenterItems centered in container
justify-contentstartItems packed at start (default)
justify-contentendItems packed at end
โš–๏ธ justify-content: space-evenly - Equal space around and between all items
Example04
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
๐Ÿ”„ justify-content: space-around - Equal space around items (half-size on ends)
Example05
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โ†”๏ธ justify-content: space-between - Equal space between items (no space on ends)
Example06
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
๐ŸŽฏ justify-content: center - Items centered in container
Example07
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โฌ…๏ธ justify-content: start - Items packed at start (default)
Example08
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โžก๏ธ justify-content: end - Items packed at end
Example09
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿ”ธ align-content Property

AttributeValueDescription
align-contentspace-evenlyEqual space around and between rows
align-contentspace-aroundEqual space around rows (half-size on ends)
align-contentspace-betweenEqual space between rows (no space on ends)
align-contentcenterRows centered in container
align-contentstartRows packed at start (default)
align-contentendRows packed at end
โš–๏ธ align-content: space-evenly - Equal space around and between all rows
Example11
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
๐Ÿ”„ align-content: space-around - Equal space around rows (half-size on ends)
Example12
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โ†”๏ธ align-content: space-between - Equal space between rows (no space on ends)
Example13
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
๐ŸŽฏ align-content: center - Rows centered in container
Example14
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โฌ†๏ธ align-content: start - Rows packed at start (default)
Example15
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output
โฌ‡๏ธ align-content: end - Rows packed at end
Example16
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿ”ธ place-content Property

AttributeValueDescription
place-contentnormalDefault behavior for content alignment
place-contentstretchStretches items to fill the container
place-contentstartAligns content to the start (top/left)
place-contentendAligns content to the end (bottom/right)
place-contentcenterCenters content vertically and horizontally
place-contentspace-betweenEqual space between rows and columns
place-contentspace-aroundEqual space around rows and columns
place-contentspace-evenlyEqual space around and between rows/columns
place-contentend startVertically aligned to end, horizontally to start
place-contentspace-between startVertical: space-between, Horizontal: start
place-contentspace-around endVertical: space-around, Horizontal: end

๐Ÿ“„ place-content: normal

Default content positioning.
Example18
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿ“ place-content: stretch

Content stretches to fill space.
Example19
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

โฌ…๏ธ place-content: start

Content aligned to top/left.
Example20
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

โžก๏ธ place-content: end

Content aligned to bottom/right.
Example21
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐ŸŽฏ place-content: center

Content centered both vertically and horizontally.
Example22
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

โ†”๏ธ place-content: space-between

Equal spacing between content blocks.
Example23
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿ”„ place-content: space-around

Equal spacing around each content block.
Example24
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

โš–๏ธ place-content: space-evenly

Equal spacing around and between content.
Example25
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿ“ place-content: end start

Bottom vertically, left horizontally.
Example26
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐Ÿงญ place-content: space-between start

Vertically spaced, horizontally left-aligned.
Example27
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output

๐ŸŽŒ place-content: space-around end

Vertically spaced, horizontally right-aligned.
Example28
โœจCode Cell
Loading Editor...
โœ๏ธ You can edit this code โ€” click Run to refresh the preview.
Output