// Tutorial //

CSS Grid Layout: The Span Keyword

Published on December 21, 2016
Default avatar

By Alligator.io

CSS Grid Layout: The Span Keyword

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

If you’re placing items onto their parent grid with grid-column or grid-row, you can use the span keyword to avoid specifying end lines when items should span more than one column or row.

Given the following CSS rule for a grid item, which spans 3 columns and 2 rows:

.item {
  grid-column: 2 / 5;
  grid-row: 1 / 3;
}

We can use the span keyword like this instead:

.item {
  grid-column: 2 / span 3;
  grid-row: 1 / span 2;
}

The end line can be provided and span used as the start line instead, in which case the span acts in reverse, so the following is also equivalent:

.item {
  grid-column: span 3 / 5;
  grid-row: span 2 / 3;
}

If multiple lines have the same name, you can define the start and end lines like in the following example:

.item {
  grid-column: col 2 / col 7;
  grid-row: content 6 / content 10;
}

The item starts on the column with the 2nd line named col and ends on the 7th line also named col. Similarly, it starts on the 6th line named row and ends on the 10th line named row.

And here the span keyword can help also, and the following is equivalent:

.item {
  grid-column: col 2 / span col 5;
  grid-row: content 6 / span content 4;
}

Span can also be used with the grid-area property. For example, if we want an item to be placed automatically, but to span across a provided number of rows and columns:

.item {
  grid-area: span 6 / span 4;
}

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up now
About the authors
Default avatar
Alligator.io

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

The 4th and 5th examples include a content keyword, but the text between talks about row. Is this a typo, or have I missed something?

.item {
  grid-column: col 2 / col 7;
  grid-row: content 6 / content 10;
}