// 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


About the authors
Default avatar
Alligator.io

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


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;
}

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.