Building Responsive Two‑Column Layouts with CSS Grid Without Frameworks
Learn how to create a responsive two‑column layout using CSS Grid, define explicit tracks with fr units, and verify the result in the browser.
30 May 2026, 10:44 UTC

The Problem: Making a Layout That Adapts Without Extra Code
When a design calls for a sidebar that stays aligned with the main content across viewport changes, developers often reach for floats, Flexbox, or a UI framework. Those approaches can add extra markup or require media‑query gymnastics to keep the two‑dimensional relationship intact.
Thesis: CSS Grid Gives You a Native Two‑Dimensional System
CSS Grid Layout lets you define rows and columns directly on a container and place child elements into those tracks without altering the document order. The fr unit distributes free space, and named areas let you refer to regions by readable identifiers.
Defining the Grid Container
Start by marking the wrapper as a grid container and setting explicit tracks. In this example we want a fixed‑width sidebar and a flexible main area.
.container {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: auto;
gap: 1.5rem;
}
Naming Areas for Clarity
Assign each logical section a name with grid‑area, then reference those names in grid‑template‑areas.
.header { grid-area: header; }
.navigation { grid-area: nav; }
.main-content { grid-area: main; }
.sidebar { grid-area: sidebar; }
.footer { grid-area: footer; }
.container {
grid-template-areas:
"header header"
"nav main"
"sidebar main"
"footer footer";
}
Worked Example: A Responsive Blog Layout
The following CSS creates a layout that stacks vertically on narrow screens while preserving the two‑column arrangement on wider viewports.
/* Base grid – two columns */
.container {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: auto;
gap: 1.5rem;
grid-template-areas:
"header header"
"nav main"
"sidebar main"
"footer footer";
}
/* Items */
.header { grid-area: header; }
.navigation { grid-area: nav; }
.main-content { grid-area: main; }
.sidebar { grid-area: sidebar; }
.footer { grid-area: footer; }
/* Stack on screens narrower than 600px */
@media (max-width: 600px) {
.container {
grid-template-columns: 1fr;
grid-template-areas:
"header"
"nav"
"sidebar"
"main"
"footer";
}
}
Trade‑off: Performance Considerations
Each explicit track adds to the browser’s style‑recalculation workload. Keeping the number of rows and columns modest (typically under ten) helps maintain smooth scrolling and interaction, especially on low‑end devices. If you find yourself defining many tracks for a complex dashboard, consider breaking the layout into smaller nested grids or using CSS Subgrid where supported.
How to Verify Your Grid
- Open the page in Chrome (or Edge) and press F12 to open DevTools.
- Select the element with class
.containerin the Elements panel. - In the Styles pane, click the Layout sidebar and enable the Grid overlay.
- You should see highlighted tracks matching the
grid-template-columnsandgrid-template-rowsvalues, and items placed according togrid-area. - To confirm that the browser is applying Grid styles, wrap your rules in a feature query:
@supports (display: grid) {
.container { /* Grid rules */ }
}
If the overlay appears, the feature query is active and the browser supports Grid. In older browsers you can provide a Flexbox fallback inside an @supports not (display: grid) block.
Actionable Closing
Begin with a simple two‑column grid, test the layout at your target breakpoints, and keep explicit tracks limited to what you need. Use the DevTools grid overlay to catch placement errors early, and fall back to Flexbox only where Grid support is missing. This approach gives you a responsive, framework‑free layout that stays maintainable as the design evolves.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.