Loading...

What are the grid-item properties?

So far, you've learned about grid-container properties, but what about grid cells and grid items? Like Flexbox layouts, containers and items have their own unique properties to enhance and customize the layout of the grid. Click through the tabs below to learn more about what properties can be applied to grid items.

As you've learned, a grid container houses grid items. By default, a grid will place one grid item per grid row, unless we explicitly tell it otherwise. When it comes to sizing and placing individual grid items, we use the following properties.

Column Row
grid-column-start row-column-start
grid-column-end row-column-end

Each property will accept one of the three values.

  • auto: This sets the grid item to default to any size explicitly outlined by the parent grid container.
  • grid line number: This sets the grid item to start on a designated line number.
  • span: This tells the grid item how many columns or rows the item should occupy.

Let's look at a familiar example...

1
2
3
4
5
6

This is a grid layout from the previous page. We can see that grid item number 3 spans two columns and that grid item number 5 spans two rows.

<style>
  .grid-container {
    display: grid;
    grid-template-columns: auto auto auto;
    grid-template-rows: auto auto;
    grid-auto-flow: column dense;
    height: 150px;
    padding: 10px;
    background-color: #40054a;
  }
  .grid-container div {
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.8);
    padding: 10px 0;
    font-size: 1.2em;
    text-align: center;
  }
  .item3 {
    grid-column-start: auto;
    grid-column-end: span 2;
  }
  .item5 {
    grid-row-start: auto;
    grid-row-end: span 2;
    }
</style>

<section class="grid-container">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
  <div class="item5">5</div>
  <div class="item6">6</div>
</section>

Let’s look at a few more examples. Look at the images below and see if you can determine what properties and values were used. Click on the images to see the code snippets for each property.

ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.
ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.
ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.
ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.
ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.
ALTTEXT: Enter key opens full-screen view with caption; escape key exits full screen.

Another way to lay out your grid items is using the grid-template-areas and the grid-area properties. The grid-template-areas property is a grid-container property that uses the grid-item property grid-area to structurally visualize our desired layout.

Click through the slideshow below to see the grid-template-areas property in action and how to use the grid-area property to accomplish it.

Lesson Content Banner

You Try!

Using your own text editor or the coding space below, test your skills on the properties we just learned! Practice different layouts and configurations and see what is and isn't possible. Try combining the grid-template-areas property, grid-area property, and the grid-row-start/stop properties and see what happens! When you think you've got the hang of it, move on to the next page in this lesson.