Skip to main content

CSS 12-Column Grid Layout

Among the ways to organize the content of a web page, a 12-column grid stands out as both common and flexible, especially for responsive design.

It cuts the horizontal space on offer into 12 columns of equal width, which gives you a precise structure for placing and sizing elements.


Benefits of a 12-Column Grid

  • Flexibility: Dividing 12 is easy, so halves (2 columns of 6), thirds (3 columns of 4), and quarters (4 columns of 3) are all possible.
  • Responsiveness: With media queries, this grid suits responsive websites, letting them adapt to desktop, tablet, or mobile screen sizes.
  • Efficiency: Design work goes faster when the grid structure is already defined.

The steps below build a basic CSS Grid layout on 12 columns:


Define the Grid Container

The grid container needs display: grid;.


Create the 12 Columns

The 12 columns are defined through the grid-template-columns property.

Writing repeat(12, [col-start] 1fr); gives 12 columns of equal width, and every column track has its start line named col-start. Piece by piece:

  • repeat(12, ..) — runs the track definition 12 times, producing 12 columns.
  • [col-start] — names a grid line. The repetition yields 12 lines called col-start, which helps when grid items must begin at specific points.
  • 1fr — a fractional unit, worth one fraction of all the space available. All 12 columns therefore get an equal, fluid width.

Place the Grid Items

Position and size grid items across the 12 columns with grid-column.

  • For an item that spans some number of columns, write grid-column: span <number>; or grid-column: <start-line> / span <number>;.
  • To say exactly which grid lines an item starts and ends on, write grid-column: <start-line> / <end-line>;.

Use Mediaqueries to Add Breakpoints

Always start from mobile: below 576 pixels wide, the sections appear in source order, stacked with the first at the top.

From 576 to 767 pixels wide, the layout has two columns.

Beyond 767 pixels wide, it has three.

Example

Here is the whole responsive 12-column grid layout, with header, navigation, content, sidebar, ads, and footer sections.

Prompt
Create a responsive 12-column CSS Grid layout with a header, navigation, content area, sidebar, ads section, and footer. Use named grid lines with repeat(12, [col-start] 1fr). Apply mobile-first design: stack all sections vertically by default, switch to a two-column layout at 576px, and a three-column layout at 768px. Style each section with a green border and beige background.
Output: complete HTML page