CSS Reference ยท Flexbox
The row-gap property
Reference for the CSS row-gap property: set the space between rows in grid layouts and between wrapped lines in flexbox, with live examples and usage notes.
The row-gap property sets the space between rows. In a grid, that is the gutter between row tracks. In a flex container that wraps, it is the space between flex lines. It is one half of the gap shorthand; the other half is column-gap.
The gap only appears between rows, not above the first row or below the last one.
.list { display: grid; row-gap: 1.5rem; }
Try it
The pink background of the container shows through the wide 24px row gaps and the narrow 4px column gap.
Syntax
row-gap: normal | <length-percentage>;
- Initial value:
normal - Applies to: multi-column containers, flex containers and grid containers
- Inherited: no
- Animatable: yes, as a length or percentage
- Computed value: as specified, with lengths made absolute
Values
| Value | Description |
|---|---|
<length> |
A non-negative length such as 20px or 1.5rem. |
<percentage> |
A percentage of the container's content-box height. If that height depends on the content (for example height: auto), percentages are unreliable, so prefer lengths. |
normal |
No gap in grid and flex layout. |
Usage notes
- Flexbox. In a single-line flex container there are no row boundaries, so
row-gaphas no visible effect untilflex-wrap: wrapcreates several lines. - Column direction. With
flex-direction: column, items stack vertically, sorow-gapspaces the items in a stack andcolumn-gapspaces the wrapped stacks. - Multi-column. Row gaps do not apply between columns of text; use
column-gapfor those. - Shorthand.
gap: 20px 8pxsets row gap 20px and column gap 8px. Writerow-gapalone when you want to change only one direction without touching the other.
Browser support
Supported in all current browsers for grid and flexbox.
Related
gapโ shorthand for bothcolumn-gapโ spacing between columnsgrid-template-rowsโ defines the row tracks- Lesson: Grid Tracks