CSS grid layout

**CSS grid layout** or **CSS grid** is a technique in Cascading Style Sheets that allows web developers to create complex responsive web design layouts more easily and consistently across browsers. There have been other webpage layout methods used previously including tables, the box model, and CSS flex box. It is currently a W3C Candidate Recommendation despite already being adopted by most major browsers.

## Motivation

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.

One issue with using floats in CSS is if 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. 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. That is where CSS grid layout shines.

## Browser support

As of October 2017, Chrome, Firefox, Safari and Edge all support CSS grid without vendor prefixes. 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 UC Browser. Web developers targeting older browsers can utilize Modernizr 3.5.0 to detect and gracefully degrade the webpage as needed.

## Utilization in frameworks

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.

## the fr unit

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

## Examples

Here is an example of the holy grail layout:

```
<html>
<style>
div { border: 1px solid; }
body {
 display: grid;
 grid-template-columns: 10em auto 10em;
 grid-template-areas:
 "header header header"
 "left middle right"
 "footer footer footer";
}
</style>
<body>
    <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>
</body>
</html>

```

Here is an example of a table of values:

```
<html>
<style>
.wrapper {
 display: grid;
 grid-template-columns: 1fr 1fr 1fr;
 grid-gap: 0.5em;
}
div {
 border: 1px solid;
}
</style>
<body>
    <div class="wrapper">
        <h3>Header1</h3><h3>Header2</h3><h3>Header3</h3>
        <div>value11</div><div>value12</div><div>value13</div>
        <div>value21</div><div>value22</div><div>value23</div>
        <div>value31</div><div>value32</div><div>value33</div>
        <div>value41</div><div>value42</div><div>value43</div>
        <div>value51</div><div>value52</div><div>value53</div>
        <div>value61</div><div>value62</div><div>value63</div>
        <div>value71</div><div>value72</div><div>value73</div>
    </div>
</body>
</html>

```