How to Draw Divider Lines Between Grid and Flex Items in CSS
To draw divider lines between grid or flex items, set a gap on the container with gap, and specify the width, style, and color of the lines with column-rule and row-rule. You don't need to add border to the items or place separate elements to act as lines. These properties work in Chrome and Edge 149 and later (Firefox and Safari do not support them yet).
The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and headless Chromium 153. I checked where the lines were drawn by reading the pixel colors in screenshots. The browser support information comes from @mdn/browser-compat-data 8.1.8. I did not test Firefox, Safari, real smartphones, or lines in multi-column layouts (column-count).
Basic usage
column-rule draws vertical lines between columns, and row-rule draws horizontal lines between rows. The value syntax is the same as border: list the width, style, and color.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
column-rule: 2px solid #00c8e8;
row-rule: 2px solid #d85878;
}
column-rule originally drew lines between columns in multi-column layouts. The CSS Gaps Module Level 1 specification, which is still in progress, extends it to grid and flex containers and adds row-rule for horizontal lines. MDN's row-rule page also describes it as the property that specifies lines drawn between rows in grid, flex, and multi-column layouts.
The following screenshot shows the CSS above rendered in the test Chromium. The lower half applies the same declarations to a flex container with flex-wrap: wrap.

In the grid, the vertical and horizontal lines run from one edge of the container to the other. Where they cross, the horizontal (pink) line was drawn on top. The stacking order is set by rule-overlap, and its initial value row-over-column puts the horizontal line on top.
In the flex container, the vertical lines are drawn only between the items in each line. Because the item widths and arrangement differ from line to line, the vertical lines do not line up across lines. The horizontal lines are drawn between wrapped lines across the full width of the container.
If you want the vertical and horizontal lines to be the same, you can set both at once with the rule shorthand.
.grid {
rule: 1px solid #9aa5ab;
}
Lines take no space and are drawn inside the gap
The specification says that lines take up no space, so adding or thickening a line does not change the placement of other elements. If a line is thicker than the gap, the neighboring item overlaps the line.
In the test environment, I compared a grid with gap: 4px with and without a 12px-wide column-rule. The position and size of the second item were the same in both cases. The gap area turned the line's color, but the parts of the line that extended beyond the gap were hidden behind the items, which had a background color.
For the same reason, if gap is 0, the line is not visible. When I changed the items to a transparent background, the line was drawn at the boundary. In other words, the line is drawn but hidden under the item backgrounds. To make the line visible, leave a gap at least as wide as the line.
Changing where lines stop at merged cells
When an item spans two columns, there is no column gap in that part of the grid. You can control where lines stop with rule-break, which sets both column-rule-break for vertical lines and row-rule-break for horizontal lines. It accepts three values:
| Value | Where the line stops |
|---|---|
normal (initial value) |
In grid, stops at T-shaped intersections and passes through cross-shaped intersections. In flex, same as none |
intersection |
Stops at both T-shaped and cross-shaped intersections |
none |
Does not stop at intersections; one continuous line runs from end to end of the gap |
To make the differences easier to see, I compared the cases with rule-inset: 6px, which shortens each end of the line by 6px. (rule-inset is explained in the next section.)

With normal, the vertical line between the first and second columns stopped at the T-shaped intersection below the two-column item and was drawn downward from 6px away from that intersection. At the cross-shaped intersection, the line was not broken and ran as one line to the bottom edge. With intersection, the line was also broken at the cross-shaped intersection, producing short lines for each cell. With none, the line was not broken at the T-shaped intersection either. It became one continuous line from 6px below the top edge of the container to 6px above the bottom edge. The part overlapping the two-column item was hidden behind the item's background. When I made the item's background transparent, the line was drawn in that part as well.
Not drawing lines next to empty cells
If not all grid cells are filled, lines are drawn next to empty cells by default. Setting rule-visibility-items to between draws lines only where items are on both sides. The around value draws lines when an item is on at least one side, and all always draws them. The initial value normal behaves the same as all in grid.
.grid {
rule-visibility-items: between;
}
I compared these settings in a 3-column by 2-row grid with only four items.

With normal, vertical lines were drawn between the empty cells in the second row, and horizontal lines were drawn above the empty cells. With between, the vertical lines remained only in the first row, and the horizontal lines remained only between items 1 and 4. The specification says this property applies to grid and multi-column containers, and flex is not included.
Shortening the ends of lines
Setting rule-inset moves the start and end of a line inward by the specified length. Use it when you want a line to stop short of the container edges.
.grid {
rule-inset: 6px;
}
The rule-break screenshot in the previous section uses this setting. The lines were drawn 6px away from the container edges and from the intersections where they stop. The specification also defines finer properties such as column-rule-inset-cap and column-rule-inset-junction, which set different lengths for the edge side and the intersection side.
Changing colors for each line
When you list colors or widths separated by commas, they apply to the gaps from left to right. If the number of columns is not fixed, you can write a repeating section with repeat(auto, ...). I tested the syntax from the specification example with a 5-column grid.
.grid {
column-rule: 2px solid;
column-rule-color: #9aa5ab, repeat(auto, #00c8e8, #d85878), #9aa5ab;
}
The four vertical lines were gray, light blue, pink, and gray from left to right. The first and last lines are gray, and the lines between them alternate between light blue and pink.
Preparing for browsers without support
According to @mdn/browser-compat-data 8.1.8, grid and flex line properties such as row-rule and rule-break are supported in Chrome and Edge 149 and later. Firefox and Safari (including iOS) do not support them.
If you want to apply the line declarations only in browsers that support them, you can separate them with @supports. In the test Chromium, CSS.supports("(row-rule: 1px solid)") returned true.
@supports (row-rule: 1px solid) {
.grid {
column-rule: 1px solid #9aa5ab;
row-rule: 1px solid #9aa5ab;
}
}





