purpose¶
to create grid-based layouts, obviously
historical note
creating this kind of layout has been a challenging task in the past
the
<table>tag has long been overused to address that sort of needstwitter’s
bootstraphas been used for this too at some pointdo not use these tools for that in 202x !
ex1 - proportional columns¶
next snippet demontrates:
a proportional grid of [3 rows ⨉ 4 columns]
with 4 areas defined, based on that tiling
header,main,sidebar, andfooterand 4
<div>s that are mapped on these areas e.g.grid-area: header
all this in one property:

ex2 - partially fixed columns¶
mostly the same, but :
we can specify fixed size for some columns
only change is to replace
grid-template-columns: 1fr 1fr 1fr 1frwithgrid-template-columns: 100px 1fr 5% 1fr;
and now
the first column has a fixed size
the third column has a size proportional to the page width
and columns 2 and 4 equally share whatever is left in width
ex3 - on rows too¶
in the previous examples :
we have not imposed anything on the height of the result
each box gets its height based on its content
it is also possible - although less often needed
to fix a height globally and arrange the rows accordingly
only change is to add on the grid:
height: 100vhto say we want to use all viewport heightgrid-template-rows: 50px 1fr 100px;
which specifies how to use vertical space
width and height do not behave quite the same !
you may not have realized it yet, but because in Western languages we read from left to right and top to bottom, the horizontal and vertical directions are not quite symmetrical when it comes to page layout
think of the width of a document as something fixed (by the device screen size), but its height depends on the content...
this is why setting grid-template-rows is less often needed than setting grid-template-columns
assignment: the css-tricks page¶
browse quickly - but entirely - the very good introduction to grids that can be found on css-tricks.com so as to get a good grip of what’s achievable
optional game
you may also complete this game https://