Learn & Understand

Grid vs Flexbox, and How CSS Layout Escaped the Float Era

In a hurry? Skip straight to the numbers.

Open the CSS Grid Calculator →

The companion calculator computes exact pixel column widths for a fixed-width grid. That precise arithmetic is useful, but it also points to something worth appreciating: CSS Grid represents the culmination of a long, painful evolution in how the web does layout. For years, arranging elements on a page meant abusing tools never designed for it. Understanding how Grid and its companion Flexbox freed developers from those hacks, when to reach for each, and the units and gotchas involved, turns a column calculation into fluency with modern layout.

The Bad Old Days

Before Grid and Flexbox, CSS had no proper layout system, so developers improvised with tools meant for other purposes. HTML tables, designed for tabular data, were misused to structure whole pages. The float property, intended to wrap text around images, was pressed into service to create columns, requiring clearfix hacks and fragile workarounds to behave. Centering something vertically was a legendary source of frustration. These approaches were brittle, verbose, and hard to make responsive. The modern layout modules exist because this era was genuinely painful, and knowing that history explains why Grid and Flexbox feel like such a relief.

Grid vs Flexbox: 2D vs 1D

The two modern systems are complementary, and the clearest way to choose between them is dimensionality.

When to use Grid versus Flexbox
CSS GridFlexbox
DimensionsTwo (rows and columns together)One (a row or a column)
Best forOverall page and component layoutsDistributing items along a line
ExampleA dashboard grid, a page skeletonA navbar, a row of buttons, toolbar

Grid is two-dimensional: it lays out content in rows and columns simultaneously, ideal for the overall structure of a page or a complex component. Flexbox is one-dimensional: it arranges items along a single axis and excels at distributing space among a row or column of elements. They are not rivals but partners, a common pattern is Grid for the page skeleton with Flexbox handling the contents of individual areas. Choosing the right one is mostly a matter of whether you are arranging in one direction or two.

The fr Unit and Intrinsic Sizing

Grid introduced a genuinely new unit, the fraction (fr), which distributes available space proportionally after fixed sizes are accounted for. This is what makes Grid so powerful for responsive layouts: columns can be told to share the remaining space in ratios, adapting automatically to the container without manual pixel math. Grid also supports intrinsic sizing keywords that size tracks to their content or to sensible minimums and maximums. The pixel-precise calculation the companion tool provides is for the cases where you need exact fixed widths, matching a mockup or aligning with fixed-size elements, but much of Grid's day-to-day power comes from letting fr units and intrinsic sizing handle proportions automatically.

The box-sizing Gotcha

One enduring trap deserves mention because it underlies so much layout confusion: how the box model calculates width. By default, an element's specified width does not include its padding and border, so adding padding makes the element wider than its stated width, breaking careful layouts. The near-universal fix is to set box-sizing to border-box, which makes the width include padding and border, so an element stays the size you asked for. Setting this globally is one of the first things experienced developers do, precisely because the default behavior causes so many "why is this too wide?" mysteries. Understanding the box model is foundational to any width calculation being correct.

Laying Out With Modern CSS

Use the calculator for exact column widths when you need them, and place it in the context of modern layout: reach for Grid for two-dimensional page and component structures and Flexbox for one-dimensional rows and columns, lean on the fr unit and intrinsic sizing for responsive proportions rather than pixel math where you can, and set box-sizing to border-box to keep widths predictable. The calculation gives the pixels; understanding Grid, Flexbox, and the box model is what makes layout finally sane.

Ready to Put This Into Practice?

Now that you understand how it works, plug in your own numbers and get an instant, accurate result.

Use the CSS Grid Calculator Now →