CSS grid layout

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

In Cascading Style Sheets, CSS grid layout or CSS grid creates complex responsive web design layouts more easily and consistently across browsers.[1] There have been other methods for controlling web page layout methods, such as tables, the box model, and CSS flex box. CSS grid is currently not an official standard (it is a W3C Candidate Recommendation) although it has been adopted by most major browsers.[2]


A depiction of a typical webpage layout using CSS floats.

CSS grid can create more asymmetrical layouts than the previous grid and layout options like CSS floats. It also allows for more standardized code that works across browsers. This is in contrast to relying on specific browser hacks or complicated workarounds.[2]

One issue with exploiting floats in CSS is that if the content gets added to one portion of the page it could disrupt the flow of the page and break the layout. This is due to the varying heights for layout elements.[2] Though CSS flex box supports flexible layouts and provides the flexibility of creating complex layouts, it fails when the need for creating responsive layouts in 2-dimensional space arises.

Browser support[edit]

As of October 2017, Chrome, Firefox, Safari and Edge all support CSS grid without vendor prefixes.[3][4][5] IE 10 and 11 support CSS grid but with an outdated specification. On mobile, all modern browsers support CSS grid except for Opera Mini and brave Browser. Web developers targeting older browsers can utilize Modernizr 3.5.0 to detect and gracefully degrade the webpage as needed. [6]

Utilization in frameworks[edit]

There are no current web frameworks that incorporate CSS grid, in contrast with CSS flex box which is used in frameworks such as Bootstrap 4 and Foundation 6.[7]

the fr unit[edit]

The "fr" unit is often used with CSS grid layout.[8][9][10] The "fr" unit, part of the CSS grid layout specification, represents a fraction of the leftover space in the grid container.[11]


Here is an example of the holy grail layout:

CSS Grid Holy Grail Layout
div { border: 1px solid; }
body {
    display: grid;
    grid-template-columns: 10em auto 10em;
        "header header header"
        "left   middle right"
        "footer footer footer";
    <div style="grid-area: header">The header</div>
    <div style="grid-area: footer">The footer</div>
    <div style="grid-area: left">The left panel</div>
    <div style="grid-area: middle; height: 200px">The main content area</div>
    <div style="grid-area: right">The right panel</div>

Here is an example of a table of values:

A simple implementation of the CSS Grid layout demonstrating a table layout
.wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 0.5em;
div { 
    border: 1px solid; 
    <div class="wrapper">


  1. ^ "CSS Grid – Table layout is back. Be there and be square". Google. Retrieved 6 October 2017.
  2. ^ a b c "CSS Grid Layout Module Level 1". W3C. 9 May 2017. Retrieved 7 October 2017.
  3. ^ Anderson, Kareem (13 September 2017). "Microsoft's newest browser gets a significant boost with EdgeHTML 16". Retrieved 7 October 2017.
  4. ^ Protalinski, Emil (9 March 2017). "Chrome 57 arrives with CSS Grid Layout and API improvements | VentureBeat". VentureBeat. Retrieved 7 October 2017.
  5. ^ "CSS Grid Layout". Can I Use. Retrieved 7 October 2017.
  6. ^ Ates, Faruk. "Modernizr 3.5.0".
  7. ^ "Flexbox grids and frameworks".
  8. ^ "CSS Grid Layout: The Fr Unit".
  9. ^ "Fractional.".
  10. ^ "An Introduction to the `fr` CSS unit"
  11. ^ "Flexible Lengths: the 'fr' unit"

External links[edit]