A track set to fr takes a share of what is left over. Fixed and auto tracks are measured first, then the fr tracks split the rest.
Col and Row are the track an item starts in. Wide and Tall are how many tracks it covers.
Size the tracks, place the items, and take the HTML with you.
A track set to fr takes a share of what is left over. Fixed and auto tracks are measured first, then the fr tracks split the rest.
Col and Row are the track an item starts in. Wide and Tall are how many tracks it covers.
CSS Grid is the layout system you use when a design has both columns and rows to think about. You describe the tracks once on the parent, then each child says which tracks it sits in, and the browser handles the rest. The trouble is that the properties come in a large family, the syntax for placement has three or four different spellings, and a small mistake shows up as a layout that is subtly wrong rather than obviously broken.
A generator turns that into something you can see. Add a column, change its unit, watch the preview redraw. Give an item a name and a span, and the code updates with it. Nothing is hidden behind an abstraction, so what you copy is the same CSS you would have written by hand, just without the trial and error.
What makes this one different is the map. Switch item positions to named areas and the tool writes the grid-template-areas block for you, one quoted string per row, so the CSS itself becomes a picture of the layout. It also checks whether the map is legal before printing it. Named areas have to be rectangles, and if two of your items overlap in a way that breaks that rule, the tool says which item is at fault and quietly falls back to line numbers rather than handing you CSS the browser will throw away.
fr for a share of the leftover space, px or rem for something fixed, and auto when the content should decide.Grid earns its place whenever the layout is two dimensional. If you only care about one direction, flexbox is usually the shorter answer.
repeat(auto-fit, minmax(220px, 1fr)), which fits as many cards per row as will comfortably go, at any screen size, with no media queries.auto for the labels and 1fr for the fields lines everything up without a table.Laying out in one direction instead? The CSS Flexbox Generator covers rows and columns of items that size themselves. For the pieces inside the layout, the CSS Box Shadow Generator and the CSS Border Radius Generator handle the card styling. Or browse all our free developer tools.
It's a share of the space that's left after everything else has been measured. Give three columns 1fr 2fr 1fr and the leftover space is cut into four parts, with the middle column taking two of them. The important word is leftover. Fixed tracks, gaps and any auto track that grew to fit its content are all subtracted first, so an fr track is never a fixed fraction of the container.
Because 1fr is really minmax(auto, 1fr), and that auto minimum refuses to shrink below the widest thing inside the track. One long word, a wide image or a table will hold the whole column open. The fix is minmax(0, 1fr), which lets the track shrink past its content, and then overflow: hidden or min-width: 0 on the child if you want the content to wrap.
Named areas when the layout is a set of distinct regions that tile neatly, because the CSS reads like a diagram and rearranging it in a media query is a matter of retyping the map. Line numbers when items overlap, when spans are computed, or when the same grid holds a variable number of children. You can mix them, but not for the same item.
Often not. repeat(auto-fit, minmax(220px, 1fr)) gives you a card grid that reflows at every width on its own, which is what the wrapping mode here generates. Media queries still earn their keep when the layout has to change shape rather than just count, such as a sidebar that becomes a top bar on a phone. That's usually one query redefining grid-template-areas.
Both create as many tracks as will fit. The difference shows up when there aren't enough items to fill the row. auto-fill leaves the empty tracks in place, so three cards in a six track row stay card sized and sit on the left. auto-fit collapses the empty tracks to zero, so those three cards stretch to fill the whole row. Neither is right in general. It depends on whether you want a steady card width or a full row.
Check that you're setting it on the grid container rather than on the items, and that the element really is display: grid and not still display: block. The other classic is space-between on justify-content in a grid whose columns are all fr. There's no free space left to distribute, so the alignment appears to do nothing while gap is working fine.
Yes, for anything you're likely to support. Every current browser has shipped it since 2017, and subgrid, the last big piece, landed everywhere in 2023. The one thing to watch is the old grid-gap spelling, which was renamed to gap years ago and is only needed for Safari 11 and earlier. This tool emits gap, which every current browser understands. Print stylesheets in some browsers still handle grid poorly.