Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Specify grid columns, rows, and areas at once with the grid-template shorthand

    Rory SmithRory Smith

    We can specify grid columns, rows, and areas in one property using the grid-template shorthand.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    In our markup, we have three navs in a section, inside a container div, and in our CSS, our container is display-grid with a 20-pixel gutter, and it's taking up all the available height. Let's save it in this layout. We're going to have a small row on the top, and a large row underneath.

    In the small row, menu one and menu two will sit next to each other. Menu three will span both rows, and it will act as a sidebar, and main will take up the rest of the space.

    Let's set up some grid-template-areas. Now, we can map out what we just described. We can say nav1, nav2, nav3 across the top row, and underneath main, main, nav3. We'll need to width that up to each individual element using grid-area.

    There's our basic layout. Let's set up some grid-template-rows for it. The top grid line can be called headerTop. The header is going to be 1fr tall. The next grid line will be headerBottom, and it will be the same as mainTop.

    The main section will be 5fr, and mainBottom will be the name of the bottom grid line. HeaderTop is this top grid line, headerBottom and mainTop is here, and mainBottom is this grid line down here.

    Finally, let's set up some grid-template-columns. The first column can be 2fr, the second can be taking up the available space, and the side-bar column can be 1fr. Here we have a grid layout which is using grid-template-areas, grid-template-rows, and grid-template-columns.

    If we wanted to, we could specify all three of these in one shorthand property called grid-template. Grid-template acts as an ASCII art visualization of what our grid's going to look like.

    Let's write a grid-template property. We'll start with our grid-template-areas, then we'll insert our grid-template-rows, and lastly our grid-template-columns. Now we have the same layout but it's specified a shorthand way. If we look under the hood here, we can see all our values being applied separately.

    If we wanted to, we could also just pass grid-template-rows and grid-template-columns to our grid-template property if we didn't want to specify any grid-template-areas.