Grid System Concepts
Comprehensive CSS Grid layout system with precise positioning, responsive breakpoints, and visual demonstrations of element placement within the grid structure.
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.
padding: 24pxGrid:
grid-template-columns: 1fr 1fr; gap: 150pxAvailable width:
100% - 48px (padding) - 150px (gap) = content area Width: 1fr
Width: 1fr
Grid Line Positioning
(Start)
(Middle)
(End)
12-Column Grid System
Traditional 12-column grid system with responsive breakpoints. Each column is 1/12 of the available width.
Element Positioning Examples
Line-Based Positioning
grid-column: 1/3
grid-row: 1/3
grid-column: 3/4
grid-row: 1/2
grid-column: 4/5
grid-row: 1/2
grid-column: 3/5
grid-row: 2/3
Named Grid Areas
Spans 3 columns
1 column
Spans 2 columns
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.