toolqik

192 · CSS

CSS Grid Generator

Draw a grid layout: set columns and rows, then drag across cells to place named areas.

Runs in your browser
Output
Column sizes
Row sizes

Drag across the cells to add an area. Click an area’s name below to rename it.

    CSS
    
      
    HTML
    
      

    About this tool

    Set how many columns and rows you want and how big each one is, then drag across the cells to create areas such as a header, sidebar and main content. The generator writes the grid-template-columns, grid-template-rows and grid-template-areas CSS plus the matching HTML.

    Track sizes

    • 1fr: one share of the free space. 1fr 2fr makes the second column twice as wide as the first.
    • 200px, 12rem: fixed sizes.
    • auto: as big as the content needs. Typical for header and footer rows.
    • minmax(200px, 1fr): flexible, but never narrower than 200px.
    • repeat(auto-fit, minmax(220px, 1fr)): as many columns as fit, which makes card grids responsive without media queries.

    Named areas

    grid-template-areas draws the layout as text, one quoted string per row, which makes the CSS easy to read and to rearrange in a media query: change the strings and every item moves. Each area must be a rectangle, and a dot (.) marks an empty cell. With areas turned off, the generator uses line numbers (grid-column: 1 / 3) instead.

    Grid lays out in two dimensions. For a single row or column of items, the Flexbox Playground is often simpler.

    FAQ

    What does fr mean in CSS Grid?

    A fraction of the free space. Columns of 1fr 1fr 1fr are equal; 2fr 1fr makes the first twice as wide as the second.

    How do I make a responsive grid without media queries?

    Use grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)). The browser fits as many 220px-or-wider columns as possible.

    How do grid-template-areas work?

    Each quoted string is a row and each word is a cell. Give items the same name with grid-area and they fill that rectangle. Use . for empty cells.

    Can areas overlap?

    Not with grid-template-areas. Placing items by line numbers allows overlaps, which is useful for layering an image and a caption.

    Is CSS Grid supported everywhere?

    Yes, in every current browser. Subgrid is also supported in all current browsers.

    esc
    ↑↓ navigate↵ open