--- url: "https://web.dev/articles/css-animated-grid-layouts" titulek: "CSS animated grid layouts | Articles | web.dev" h1: "CSS animated grid layouts Stay organized with collections Save and categorize content based on your preferences." popis: "In CSS Grid, the `grid-template-columns` and `grid-template-rows` properties allow you to define line names and track sizing of grid columns and rows, respectively. Supporting interpolation for these properties allows grid layouts to smoothly transition between states, instead of snapping at the halfway point of an animation or transition." jazyk: "en" kanonicka: "https://web.dev/articles/css-animated-grid-layouts" drobecky: ["Articles", "CSS animated grid layouts"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 01:49:36" znaku: 2546 slov: 374 kodovani: "iso-8859-2" sha256: "c4a4c6265877bf5baa65488fa80d13aedae962b90ea5d1c43df93e5f71206b04" --- CSS animated grid layouts Stay organized with collections Save and categorize content based on your preferences. Bramus In CSS Grid, the `grid-template-columns` and `grid-template-rows` properties let you define line names and track sizing of grid columns and rows, respectively. Supporting interpolation for these properties allows grid layouts to smoothly transition between states, instead of snapping at the halfway point of an animation or transition. Browser Support 107 107 66 16 Value Interpolation in CSS In CSS you can smoothly transition properties from one value to the other using the `transition` property. `#target { opacity: 0.5; transition: opacity ease-in-out 0.25s; } #target:hover { opacity: 1; }` The rendering engine will automatically detect the type of the targeted property’s value, and use that information to smoothly transition to the new value. For example: Transitioning `opacity` from `0` to `1`? That’s a numerical interpolation. Transitioning `background-color` from `white` to `black`? Fade between the source and target colors. Transitioning `width`? Interpolate numerically, converting units along the way if needed. The same applies to CSS animations, where the browser will do value interpolation between keyframes. Animate `grid-template-columns` and `grid-template-rows` Grid layouts can also smoothly transition between states, instead of snapping at the halfway point of an animation or transition. In the following demo a grid is showing several avatars. To conserve space, the avatars are laid out on top of each other by limiting the width of each column using `grid-template-columns`. On hover, each column is given more space. `.avatars { display: grid; gap: 0.35em; grid-auto-flow: column; grid-template-columns: repeat(4, 2em); transition: all ease-in-out 0.25s; } .avatars:hover { grid-template-columns: repeat(4, 4em); }` With the `transition` property in place, the grid smoothly interpolates between values. The effect also applies to animations that change the `grid-template-columns` or `grid-template-rows` values. Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-04-26 UTC.