CSS grid-gap

Update

The CSS grid-gap property is now an alias for the gap property.

Use gap instead.

The remainder of this article outlines how this property worked before it was repurposed as an alias to gap.

Note that this was done in a backwards compatible way, so any legacy code shouldn't be impacted (i.e. any existing grid-gap code should remain working as expected).

View Output Full Screen Preview

The CSS grid-gap property is a shorthand property for setting the gutters between grid rows and columns.

If your browser supports CSS grids, the above example should look like this:

Screenshot of a grid with it's grid-gap set.

The grid-gap property is shorthand for the grid-column-gap and grid-row-gap properties. It's a convenient way to set the grid gutters, without having to write out each property name individually.

Here's how the grid the above example works.

So providing one value sets the gutter for both the rows and the columns.

If you provide two values, the first value sets the gutter for the rows, the second value sets it for the columns.

Like this:

Syntax

Here's the official syntax of the grid-gap property:

These values are explained below.

Possible Values

'grid-row-gap'
This value sets the grid-row-gap property.
'grid-column-gap'
This value sets the grid-column-gap property.

Providing only one value applies the same gutter to both the row and the column. Negative values are invalid.

In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:

initial
Represents the value specified as the property's initial value.
inherit
Represents the computed value of the property on the element's parent.
unset
This value acts as either inherit or initial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.

Basic Property Information

Initial Value
normal
Applies To
Grid containers
Inherited?
No
Media
Visual
Animation type
As length, percentage, or calc (see example)

CSS Specifications

Browser Support

Browser support for CSS properties can vary, particularly for newer or experimental features. Check current browser compatibility before using a property in production, especially when supporting older browsers.

The following table provided by Caniuse.com shows the level of browser support for this feature.

Initial Value

CSS properties have an initial value that applies when the property has not been explicitly set. The initial value is different from the value inherited from a parent element and may vary between properties.

Inheritance

Some CSS properties inherit their computed value from their parent element by default, while others do not. The inherit, initial, unset, and revert keywords can also be used to control how a property gets its value.

Vendor Prefixes

Most modern CSS properties use the standard, unprefixed syntax. Vendor-prefixed properties such as -webkit- are mainly relevant to older browser versions or specific features and should only be used when required by your browser support targets.