Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
Interesting Facts About CSS Grid
Next article icon

Interesting Facts About CSS Grid

Last Updated : 27 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSS Grid is one of the most powerful layout systems in CSS. Let’s explore some interesting facts about CSS Grid that will help you use it more effectively.

1. Overlapping Items Made Easy

CSS Grid allows you to easily position items in a way that they overlap one another, which is difficult to achieve with traditional layout methods.

  • No Negative Margins: Unlike Flexbox, you don’t need to use negative margins to overlap items.
  • Creative Designs: Perfect for creating layered, magazine-style layouts.
HTML
<html> <head>     <style>         .container {             display: grid;             grid-template-columns: 1fr 1fr;             grid-template-rows: 100px 100px;             gap: 10px;         }         .item1 {             grid-column: 1 / 3;             grid-row: 1 / 2;             background-color: lightcoral;         }         .item2 {             grid-column: 1 / 2;             grid-row: 2 / 3;             background-color: lightblue;         }     </style> </head> <body>     <div class="container">         <div class="item1"></div>         <div class="item2"></div>     </div> </body> </html> 
  • .item1 spans two columns and one row, while .item2 occupies just one column and row.
  • The items overlap due to the grid positioning properties.

2. Span Multiple Rows and Columns

You can make grid items span across multiple rows or columns, giving you more flexibility in arranging content.

  • Spanning items: Use grid-column and grid-row to define how many rows or columns an item should occupy.
  • Responsive layouts: Great for creating layouts that need to adapt to different screen sizes.
  • No extra wrappers needed: You can control layout directly on the items.
HTML
<html> <head>     <style>         .container {             display: grid;             grid-template-columns: repeat(3, 1fr);             grid-template-rows: 100px 100px;             gap: 10px;         }         .item {             background-color: lightgreen;         }         .item1 {             grid-column: span 2;         }     </style> </head> <body>     <div class="container">         <div class="item item1"></div>         <div class="item"></div>         <div class="item"></div>     </div> </body> </html> 
  • .item1 spans two columns, while the other items take up one column each.
  • grid-template-columns: repeat(3, 1fr) defines three equal-width columns in the grid.

3. Automatic Sizing Based on Content

CSS Grid can automatically adjust the size of rows and columns based on the content inside the grid items.

  • Content-based sizing: The grid automatically adjusts rows and columns to fit their content.
  • No manual sizing: You don’t need to set fixed dimensions for your rows and columns.
  • Perfect for responsive designs: Grid adapts to changes in content size automatically.
HTML
<html> <head>     <style>         .container {             display: grid;             grid-template-columns: repeat(3, auto);             gap: 10px;         }         .item {             background-color: lightyellow;         }     </style> </head> <body>     <div class="container">         <div class="item">Short text</div>         <div class="item">A longer text that will affect the column width</div>         <div class="item">More text</div>     </div> </body> </html> 
  • grid-template-columns: repeat(3, auto) ensures that each column's width adjusts based on its content.
  • The container automatically adjusts based on the size of the content in the grid items.

4. Create Complex Layouts with Simple Code

CSS Grid enables you to create complex layouts with just a few lines of code, saving time and effort.

  • Simplified layout creation: Define rows and columns once and place content in them.
  • No floats or clearfixes: No need for complex CSS hacks like floats or clearfix.
  • Efficient grid system: Easily adjust the number of rows and columns.
HTML
<html> <head>     <style>         .container {             display: grid;             grid-template-columns: 200px 1fr 200px;             grid-template-rows: 100px auto 100px;             gap: 10px;         }         .header {             grid-column: 1 / 4;             background-color: lightgray;         }         .sidebar {             grid-row: 2 / 3;             background-color: lightblue;         }         .content {             background-color: lightgreen;         }     </style> </head> <body>     <div class="container">         <div class="header">Header</div>         <div class="sidebar">Sidebar</div>         <div class="content">Content</div>     </div> </body> </html> 
  • grid-template-columns: 200px 1fr 200px creates three columns (sidebar, content, sidebar).
  • The header spans across all columns, and the sidebar is placed in the second row.

Next Article
Interesting Facts About CSS Grid

A

anujpaz9pe
Improve
Article Tags :
  • CSS
  • Web Technologies

Similar Reads

    Foundation CSS XY Grid Auto Sizing
    Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to layout stunning responsive websites, apps, and emails that appear amazing & can be accessible to any device. In this article, we will discuss the XY Block Grid
    2 min read
    Primer CSS Float based Grid
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by
    2 min read
    Tailwind CSS Grid Auto Rows
    This class accepts more than one value in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS grid-auto-rows property. This class is used to specify the size for the rows of implicitly generated grid containers. This class is used to utilities to c
    3 min read
    Foundation CSS Kitchen Sink Grid
    Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to layout stunning responsive websites, apps, and emails that appear amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Mo
    3 min read
    Primer CSS Grid Nesting
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences