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 Layout Example

CSS Grid

CSS Grid Layout Example

A CSS Grid Layout combines rows, columns, and spacing to create structured and responsive web page layouts.

In real-world projects, CSS Grid is commonly used for:

  • Website layouts
  • Dashboards
  • Admin panels
  • Product galleries
  • Portfolio websites

This lesson demonstrates how to build a complete grid layout using the concepts learned in previous lessons: The supporting concepts are explained in Grid Placement and Grid Areas.

  • Grid Container
  • Grid Columns
  • Grid Rows
  • Grid Gap

Syntax

A typical grid layout uses:

CSS Grid Layout Syntax

css

.container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

This creates a responsive three-column grid with spacing between items.

Attributes

PropertyDescriptionExample
displayCreates grid containerdisplay: grid;
grid-template-columnsDefines columnsrepeat(3, 1fr);
grid-template-rowsDefines rowsauto;
gapSets spacing between itemsgap: 20px;
repeat()Repeats rows or columnsrepeat(4, 1fr);

Example

CSS Grid Layout Example Complete Example

html

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

Browser Support

Feature
Chrome
Edge
Firefox
Safari
CSS Grid layout57165210.1

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

Notes

  • CSS Grid is ideal for two-dimensional layouts.
  • The repeat() function reduces repetitive code.
  • Grid layouts automatically adapt to content placement.
  • Gap spacing keeps layouts organized.
  • CSS Grid works well with responsive design techniques.

Responsive Grid Example

Responsive Grid Example

css

.container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

Automatically adjusts the number of columns based on available screen width.

Common Grid Layouts

Layout TypeColumns
Two Column Layoutrepeat(2, 1fr)
Three Column Layoutrepeat(3, 1fr)
Four Column Layoutrepeat(4, 1fr)
Responsive Layoutauto-fit + minmax

Conclusion

CSS Grid Layout provides a powerful and flexible way to create modern web page structures. By combining grid containers, rows, columns, and gaps, developers can build clean, responsive, and maintainable layouts with minimal code.

PreviousCSS Grid GapNextGrid Placement