Category · Feature Sections Difficulty Level · Intermediate Published on · May 15, 2024

CSS Grid Layout System

A responsive CSS grid layout system for creating modern web page structures with minimal code.

#grid #layout #responsive #css #framework

Responsive Design

Yes

Dark Mode Support

No

lines

190

Browser Compatibility

No

Live Preview

Interact with the component without leaving the page.

400px

CSS Grid Layout System

This responsive grid system provides a flexible foundation for creating modern web layouts. It’s built with CSS flexbox and uses a 12-column structure that adapts to different screen sizes.

Features

  • Responsive 12-column grid system
  • Mobile-first approach with breakpoints for different devices
  • Nested grid support for complex layouts
  • Clean, minimal CSS with no dependencies
  • Easy to customize and extend

Usage

The grid system uses class-based naming similar to popular CSS frameworks:

  • .grid-container - Contains the entire grid
  • .grid-row - Creates a horizontal row of columns
  • .grid-col - Base class for all columns
  • .col-{size} - Sets column width (1-12)
  • .col-md-{size} - Sets column width on medium screens and up
  • .col-lg-{size} - Sets column width on large screens and up
  • .col-xl-{size} - Sets column width on extra large screens

Customization

You can easily customize this grid system by:

  1. Changing the max-width of .grid-container
  2. Adjusting the gutter width (padding in .grid-col)
  3. Modifying breakpoints in media queries
  4. Adding additional breakpoints as needed

This grid system provides a solid foundation for responsive layouts while remaining lightweight and easy to understand.

HTML

46

lines

CSS

117

lines

JavaScript

27

lines


                <div class="grid-container">
  <div class="grid-row">
    <div class="grid-col col-12 col-md-6 col-lg-4">
      <div class="content-box">
        <h3>Column 1</h3>
        <p>This is a responsive column that will resize based on screen width.</p>
      </div>
    </div>
    <div class="grid-col col-12 col-md-6 col-lg-4">
      <div class="content-box">
        <h3>Column 2</h3>
        <p>This column will stack on mobile and display side by side on larger screens.</p>
      </div>
    </div>
    <div class="grid-col col-12 col-md-12 col-lg-4">
      <div class="content-box">
        <h3>Column 3</h3>
        <p>The grid system supports different column widths at various breakpoints.</p>
      </div>
    </div>
  </div>
  
  <div class="grid-row">
    <div class="grid-col col-12 col-md-4">
      <div class="content-box">
        <h3>Nested Grid</h3>
        <p>You can nest grid rows inside columns for complex layouts.</p>
        
        <div class="grid-row">
          <div class="grid-col col-6">
            <div class="nested-box">Nested 1</div>
          </div>
          <div class="grid-col col-6">
            <div class="nested-box">Nested 2</div>
          </div>
        </div>
      </div>
    </div>
    <div class="grid-col col-12 col-md-8">
      <div class="content-box">
        <h3>Flexible Sizing</h3>
        <p>This column takes up 8/12 of the available space on medium screens and above.</p>
      </div>
    </div>
  </div>
</div>

              
46lines
1469characters
HTMLLanguage

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library →