CSS display: grid vs inline-grid
display: grid creates a block-level container in normal flow and lays out its children in a grid. display: inline-grid uses the same inner layout, but the container itself can sit on a line with surrounding text. Neither declaration sets the number of columns by itself.
Separate outer placement from inner layout
The display property controls how a box participates in the surrounding layout and what layout it uses for its contents. In two-keyword form, grid is block grid and inline-grid is inline grid. The example uses the single-keyword forms. See CSS Display · The display properties.
| Declaration | Outer placement | Child layout |
|---|---|---|
display: grid |
Block-level in normal flow. | Grid |
display: inline-grid |
Inline-level. It can sit on a line with nearby content. | Grid |
Compare a normal block, two grids, and an inline grid
Save and open the example as grid-display.html. It does not need external files or JavaScript. Each sample contains the same items A, B, C, and D, so you can compare the parent’s display type and column settings.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare grid and inline-grid</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; } h2 { margin: 16px 0 4px; font-size: 18px; }
.sample, .line { max-width: 420px; padding: 10px; border: 1px solid #7795a3;
background: #edf5f7; }
.item { min-width: 0; min-height: 40px; padding: 8px;
border: 1px solid white; background: #176f80; color: white; text-align: center; }
.single { display: grid; gap: 8px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.inline { display: inline-grid; grid-template-columns: repeat(2, 60px);
gap: 8px; padding: 8px; background: #ffe3a0; vertical-align: middle; }
</style>
</head>
<body>
<h1>Compare Grid display values</h1>
<h2>Normal block</h2>
<div class="sample plain">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
<h2>grid: one implicit column</h2>
<div class="sample single">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
<h2>grid: two defined columns</h2>
<div class="sample two">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
<h2>inline-grid: a grid in a line of text</h2>
<div class="line">
<span>Before</span>
<div class="inline">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
<span>After</span>
</div>
</body>
</html>
In the first sample, the child blocks are stacked vertically. The second also has one column, but it’s already a grid, so gap: 8px adds space between the items. The third defines two columns, placing A and B in the first row and C and D in the second.
The last gold grid can sit on the same line as the text on either side. vertical-align: middle adjusts the inline grid box in that line. Its inner items have their own alignment. This describes the normal inline flow in the example. When an inline-grid box is itself a flex or grid item, its outer display type is blockified. See CSS Display · Automatic box type transformations.
Why a grid can still have one column
Without an explicit column or item placement, the example’s default grid-auto-flow: row creates one implicit column and fills it downwards. The following grid-template-columns rule creates two columns without changing the HTML. See CSS Grid · Grid item placement algorithm.
.container {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
Four items in two columns create two rows without any row definitions. A fifth item starts a third row. A typical grid item is a direct child box participating in that grid. A heading inside a card does not become a separate cell in the outer grid. Set a layout on the card if its contents need their own grid. See CSS Grid · Grid items.
Measure the container separately from the tracks
At an outer width of 420px, the third grid has 398px after its border and padding. Subtract the 8px gap and divide the remainder to get 195px per column. The inline grid uses two fixed 60px columns plus an 8px gap and 16px of horizontal padding. Its outer width is 144px when there’s room for the box.
Add width: 100% to .inline. The gold box now fills the parent’s content width, so the neighboring text and box cannot sit on one line. The two inner columns remain 60px each. On a very narrow line the fixed tracks can overflow. Remove the width declaration after trying it.
If the result is unexpected, check the parent’s computed display and the direct children in developer tools. Then look for a later or more specific rule changing grid-template-columns. As a comparison, set only .two to display: block. Its children stack and the grid gap disappears. Restore display: grid afterward.




