Day 97: animating grids

It’s possible to animate gap, grid-template-columns, and grid-template-rows.Almost 6 years ago I wrote a blog post on CodePen titled “Animating CSS Grid Layout properties”. A lot has changed since then, especially recen…


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović

It’s possible to animate gap, grid-template-columns, and grid-template-rows.

Almost 6 years ago I wrote a blog post on CodePen titled “Animating CSS Grid Layout properties”. A lot has changed since then, especially recently, and I wanted to update the post, but the blogging feature on CodePen has been sunset and I can’t edit the post anymore. Since animating grids is topical again, I added it to the series.

According to the CSS Grid Layout Module Level 1 specification there are 5 animatable grid properties:

  • grid-gap, grid-row-gap, grid-column-gap
    as length, percentage, or calc.
  • grid-template-columns, grid-template-rows
    as a simple list of length, percentage, or calc, provided the only differences are the values of the length, percentage, or calc components in the list.

Animating these properties will most likely affect larger areas of the screen. That's why it's important to only show animation to those who have no preference for reduced motion.

.grid {
  --col: 9.5rem;
  --row: 8rem;
  --gap: 2rem;

  display: grid;
  grid-template-columns: repeat(3, var(--col));
  grid-template-rows: repeat(4, var(--row));
  grid-gap: var(--gap);
}

.grid--full {
  --col: 30%;
  --row: 4rem;
  --gap: 1rem;
}

@media (prefers-reduced-motion: no-preference) {
  .grid {
    transition: all 1s;
  }
}

See the Pen CSS Grid Layout: Animation by Manuel Matuzovic (@matuzo) on CodePen.

Browser support for animatable grid properties
Browser (grid-)gap, (grid-)row-gap, (grid-)column-gap grid-template-columns grid-template-rows
Firefox 66 (since FF 55, FFM 53)
Safari 16
Chrome 107 (since Chrome 68)
Edge 107 (since Edge 79)

Other demos

See the Pen Animated Mondrian (CSS grid-template-columns|rows interpolation) by web.dev (@web-dot-dev) on CodePen.

See the Pen Animated CSS Grid by web.dev (@web-dot-dev) on CodePen.

My blog doesn't support comments yet, but you can reply via blog@matuzo.at.


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2023-02-07T00:00:00+00:00) Day 97: animating grids. Retrieved from https://www.scien.cx/2023/02/07/day-97-animating-grids-2/

MLA
" » Day 97: animating grids." Manuel Matuzović | Sciencx - Tuesday February 7, 2023, https://www.scien.cx/2023/02/07/day-97-animating-grids-2/
HARVARD
Manuel Matuzović | Sciencx Tuesday February 7, 2023 » Day 97: animating grids., viewed ,<https://www.scien.cx/2023/02/07/day-97-animating-grids-2/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 97: animating grids. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/07/day-97-animating-grids-2/
CHICAGO
" » Day 97: animating grids." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2023/02/07/day-97-animating-grids-2/
IEEE
" » Day 97: animating grids." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2023/02/07/day-97-animating-grids-2/. [Accessed: ]
rf:citation
» Day 97: animating grids | Manuel Matuzović | Sciencx | https://www.scien.cx/2023/02/07/day-97-animating-grids-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.