HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Grid Gap

CSS Grid

CSS Grid Gap

The CSS Grid Gap property is used to create space between grid rows and columns.

Without gaps, grid items appear directly next to each other. The gap property improves readability and layout design by adding spacing between grid items. The supporting concepts are explained in CSS Grid Columns and CSS Grid Rows.

CSS Grid provides three related properties:

  • gap
  • row-gap
  • column-gap

These properties help create clean and professional-looking grid layouts.

Syntax

Using Gap

Gap Syntax

css

.container {
    gap: value;
}

Gap Example

css

.container {
    gap: 20px;
}

Adds 20px spacing between all rows and columns.

Using Row Gap

Row Gap Example

css

.container {
    row-gap: 20px;
}

Adds vertical spacing only.

Using Column Gap

Column Gap Example

css

.container {
    column-gap: 30px;
}

Adds horizontal spacing only.

Attributes

PropertyDescriptionExample
gapSets spacing for rows and columnsgap: 20px;
row-gapSets spacing between rowsrow-gap: 15px;
column-gapSets spacing between columnscolumn-gap: 25px;
gapMultiple valuesgap: 10px 20px;
inheritInherits gap from parentgap: inherit;

Example

CSS Grid Gap Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Grid Gap Example</title>
    <style>
        .container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 20px;
            border: 2px solid black;
            padding: 10px;
        }
        .item {
            background-color: lightblue;
            padding: 20px;
            text-align: center;
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
        <div class="item">Item 4</div>
        <div class="item">Item 5</div>
        <div class="item">Item 6</div>
    </div>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
gap in Grid66166112

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • gap is the preferred modern property.
  • gap: 20px; applies spacing to both rows and columns.
  • gap: 10px 20px; means row gap = 10px and column gap = 20px.
  • Works in both CSS Grid and Flexbox.
  • Makes layouts cleaner than using margins on individual items.

Single Gap Value

Single Gap Value

css

gap: 20px;

Equal spacing everywhere.

Different Row and Column Gaps

Different Row and Column Gaps

css

gap: 15px 30px;

15px row gap
30px column gap

Separate Properties

Separate Properties Example

css

row-gap: 20px;
column-gap: 40px;

Conclusion

The CSS Grid Gap property provides a simple and efficient way to add spacing between grid items. By using gap, row-gap, and column-gap, you can create cleaner, more organized, and visually appealing grid layouts without adding extra margins to individual elements.

PreviousCSS Grid RowsNextCSS Grid Layout Example