Layouts built with floats and nested wrappers used to be fragile. CSS Grid lets you describe the page in two dimensions: rows and columns at once. With named areas, the code even looks like the layout. The CSS Grid Generator helps you set up the columns, rows and gap visually and copy the container CSS, so you can focus on content.
CSS Grid Generator FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool →Sketch the layout first
Draw four boxes: a header across the top, a sidebar on the left, the main content on the right and a footer across the bottom. Decide the sizes. A common choice is a sidebar of 240 px and a flexible content area. In Grid terms: two columns, 240px and 1fr, and three rows, auto, 1fr and auto.
Build it step by step
- Type the column and row sizes into the generator, for example 240px 1fr for columns and auto 1fr auto for rows.
- In your own CSS, make the header and footer span both columns.
- Place the sidebar in the left column of the middle row and the content in the right column, also in your own CSS.
- Copy the generated container CSS and add the rules for the child items.
- Add the class names to your HTML elements and check the result in the browser.
The named-areas version
Named areas make the structure readable. The container declares grid-template-areas with lines such as "header header", "sidebar content" and "footer footer", and each child gets grid-area: header, sidebar, content or footer. To move the sidebar to the right, you only change that text, not the HTML.
Useful Grid features
- The fr unit shares available space: 1fr and 2fr give a one-to-two split.
- minmax(200px, 1fr) sets a minimum width and a flexible maximum.
- gap adds consistent spacing between cells, replacing many margins.
- min-height: 100vh on the container keeps the footer at the bottom of short pages.
- auto-fit with repeat creates responsive card grids without media queries.
Make it work on phones
A two-column layout is too cramped on a narrow screen. Add a media query, for example below 700 px, that redefines the areas as a single column: header, content, sidebar, footer, stacked in that order. Put the main content before the sidebar in the HTML so that screen readers and small screens meet the important part first, and use the grid to place visual order only when necessary.
Grid or Flexbox?
Use Grid when you place items in rows and columns together, such as a whole page or a card gallery. Use Flexbox for one-dimensional rows or columns, such as a navigation bar or the contents of one card. They combine well: a grid defines the page regions, and Flexbox aligns what is inside each region. Choosing the right one for each job keeps the CSS short and easier to change later.
Grid areas also help teams. When a designer asks to move the sidebar, the change is one line of CSS, and the HTML, which other code may depend on, stays untouched.
Common mistakes
Forgetting display: grid on the container is the usual reason nothing happens. Area names must form rectangles; an L-shaped region is not allowed. Be careful with long words or images that overflow a 1fr column, and add min-width: 0 to the child so it can shrink. Test with real content, not placeholders, and inspect the grid overlay in your browser developer tools, which shows lines and area names.
Comments (0)
No comments yet. Be the first to share a thought.