CSS Layout Methods: Flexbox vs Grid vs Traditional
Choosing the Right Layout Method
CSS offers four major layout approaches: Flexbox, Grid, Float, and Positioning. Each solves different problems. Picking the wrong one leads to fragile layouts and messy workarounds.
This guide compares all four methods so you can make the right choice quickly.
At a Glance
| Method | Dimension | Best For |
|---|---|---|
| Flexbox | 1D (row or column) | Distributing items along one axis |
| Grid | 2D (rows and columns) | Page-level layouts with both axes controlled |
| Float | N/A | Wrapping text around elements |
| Positioning | N/A | Removing elements from normal flow |
Flexbox
Flexbox arranges items in a single direction — either a row or a column. Items grow, shrink, and align dynamically within that flow.
When to use Flexbox:
- Navigation bars with items spread across a row
- Card rows where items share available space
- Centering content vertically and horizontally
- Any layout where items should distribute along one axis
/* Simple centered row */
.nav {
display: flex;
justify-content: space-between;
align-items: center;
}
Strengths: Simple one-axis alignment, content-driven sizing, easy reordering.
Weaknesses: Multi-row layouts require workarounds — Grid handles them natively.
Grid
CSS Grid arranges items in two dimensions simultaneously. You define rows and columns, then place items into specific cells or spanning areas.
When to use Grid:
- Page-level layouts with sidebars and content areas
- Dashboards with widgets spanning rows and columns
- Magazine-style layouts with items placed at exact coordinates
- Any structure where you need to control both axes
/* Dashboard layout */
.dashboard {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: 64px 1fr 48px;
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
height: 100vh;
}
Strengths: Full two-dimensional control, named areas for readability, gap support built-in.
Weaknesses: Overkill for simple single-axis layouts — Flexbox is more concise there.
Float
Float pulls an element to one side of its container, letting inline content wrap around it. Originally designed for images in text blocks, it was repurposed for entire page layouts before Flexbox and Grid existed.
When to use Float:
- Wrapping text around an image
- Floating a pull-quote or sidebar within an article
/* Text wrapping around an image */
.article-image {
float: left;
margin: 0 1.5rem 1rem 0;
max-width: 50%;
}
Strengths: Native text wrapping — the only method that does it.
Weaknesses: Requires clearfix hacks for containers, no vertical centering, fragile at responsive sizes. Avoid for general layout — use Flexbox or Grid instead.
Positioning
Positioning removes elements from normal document flow and places them at specific coordinates. Use it for overlays, tooltips, and fixed headers — not for page structure.
| Value | Relative To | Use Case |
|---|---|---|
relative | Element's normal position | Offset without affecting siblings |
absolute | Nearest positioned ancestor | Tooltips, overlays, badges |
fixed | Viewport | Sticky headers, persistent controls |
sticky | Scroll container | Section headers that pin on scroll |
/* Tooltip positioning */
.tooltip-container {
position: relative;
}
.tooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
}
Strengths: Precise placement, scroll-independent anchoring with fixed and sticky.
Weaknesses: Removed from flow — elements overlap unless you manage space manually. Not a layout system.
Decision Flowchart
Follow this sequence to pick the right method:
- Do you need text to wrap around an element? → Use Float
- Is the element an overlay, tooltip, or pinned header? → Use Positioning
- Do you control both rows and columns? → Use Grid
- Do items flow in one direction? → Use Flexbox
Most layouts fall into steps 3 or 4. Grid handles page shells and dashboards. Flexbox handles components — navbars, card lists, toolbars, and centered containers.
Same Layout, Different Methods
A simple two-column sidebar layout built three ways:
Flexbox
.layout {
display: flex;
gap: 1rem;
}
.sidebar { flex: 0 0 250px; }
.content { flex: 1; }
Grid
.layout {
display: grid;
grid-template-columns: 250px 1fr;
gap: 1rem;
}
Float (legacy)
.sidebar {
float: left;
width: 250px;
}
.content {
margin-left: 270px; /* sidebar width + gap */
}
.layout::after {
content: '';
display: table;
clear: both;
}
Grid is the cleanest for this pattern — fewer declarations, no calc workarounds. Flexbox is nearly as concise. Float requires a clearfix and manual margin math.
Combining Methods
Real projects use multiple methods together. A common pattern:
- Grid for the page shell (header, sidebar, content, footer)
- Flexbox for components inside each grid area (nav links, card rows, form layouts)
- Positioning for overlays, modals, and sticky elements
.page {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: 64px 1fr;
}
.header {
grid-column: 1 / -1;
display: flex; /* Flexbox inside a Grid area */
justify-content: space-between;
align-items: center;
}
.modal-backdrop {
position: fixed; /* Positioning for overlays */
inset: 0;
display: flex;
justify-content: center;
align-items: center;
}
Browser Support
All modern browsers fully support Flexbox, Grid, Gap, and Sticky positioning. The only concern is legacy IE11 — which no longer receives security updates and has negligible market share.
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| Flexbox | 29+ | 28+ | 9+ | 12+ |
| Grid | 57+ | 52+ | 10.1+ | 16+ |
gap in flex | 84+ | 63+ | 14.1+ | 84+ |
position: sticky | 56+ | 59+ | 13+ | 16+ |
If you need to support older browsers, use Flexbox over Grid where possible — its support predates Grid by several years.
Key Takeaways
- Flexbox for one-axis layouts, Grid for two-axis layouts
- Float only for text wrapping, Positioning only for overlays and pinned elements
- Grid is the cleanest choice for page-level structure
- Flexbox excels at component-level alignment inside grid areas
- Combine methods — each solves a different piece of the layout puzzle
- Browser support is no longer a concern for modern projects
Try It Yourself
Build and preview flex layouts interactively with our Flexbox Generator. Adjust properties visually and copy the CSS into your project.
Related Guides
- CSS Flexbox Tutorial — Deep dive into every flex container and item property
- Flexbox Generator Guide — Visual walkthrough of building layouts with a generator
- CSS Gradient Guide — Add visual depth to your layout backgrounds with gradients