Grid System Concepts

Comprehensive CSS Grid layout system with precise positioning, responsive breakpoints, and visual demonstrations of element placement within the grid structure.

24px
Container Padding
150px
2-Column Gap
12
Column System
∞
Responsive

Grid System Architecture

Core Principles

  • Two-Dimensional Layout

    Simultaneous control over rows and columns for complex layouts

  • Precise Positioning

    Line-based placement with grid-column and grid-row properties

  • Flexible Units

    fr units, percentages, and fixed measurements for responsive design

Key Properties

display: grid

Creates grid container

grid-template-columns

Defines column structure

gap

Sets spacing between items

2-Column Grid System (150px Gap)

This demonstrates a 2-column grid with 24px container padding and 150px gap between columns. Each column spans 1 fractional unit (1fr) with equal width distribution.

Container: padding: 24px
Grid: grid-template-columns: 1fr 1fr; gap: 150px
Available width: 100% - 48px (padding) - 150px (gap) = content area
Container with 24px padding
Column 1
Grid Item 1
grid-column: 1
Width: 1fr
Column 2
Grid Item 2
grid-column: 2
Width: 1fr

Grid Line Positioning

Line 1
(Start)
Line 2
(Middle)
Line 3
(End)

12-Column Grid System

Traditional 12-column grid system with responsive breakpoints. Each column is 1/12 of the available width.

1
2
3
4
5
6
7
8
9
10
11
12
Example spans: Columns 1-6 (6 cols), 7-8 (2 cols), 9-9 (1 col), 10-11 (2 cols), 12-12 (1 col)

Element Positioning Examples

Line-Based Positioning

Item 1
grid-column: 1/3
grid-row: 1/3
Item 2
grid-column: 3/4
grid-row: 1/2
Item 3
grid-column: 4/5
grid-row: 1/2
Item 4
grid-column: 3/5
grid-row: 2/3

Named Grid Areas

Header
Spans 3 columns
Nav
1 column
Main
Spans 2 columns
Footer
Spans 3 columns

Grid vs Flexbox: When to Use Each

Use CSS Grid When:

  • You need 2D layouts (rows AND columns)
  • Precise element positioning is required
  • Creating complex page layouts
  • Overlapping content is needed

Use Flexbox When:

  • You need 1D layouts (row OR column)
  • Content-based sizing is important
  • Aligning items within containers
  • Simple component layouts

Interactive Grid Playground

Experiment with different grid configurations. Click the buttons below to see how elements position themselves within the grid system.

Element A
Column 1
Element B
Column 2
Back to Experiments