CSS Grid Calendar Layout Generator
A seven-column month grid with a weekday header and events that span days.
Named areas. The CSS is a picture of the layout, and only the properties that actually change get repeated inside each media query.
.calendar {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: auto auto minmax(60px, auto) minmax(60px, auto);
gap: 2px;
grid-template-areas:
"toolbar toolbar toolbar toolbar toolbar toolbar toolbar"
"mon tue wed thu fri sat sun"
"w1-1 w1-2 w1-3 w1-4 w1-5 w1-6 w1-7"
"w2-1 w2-2 w2-3 w2-4 w2-5 w2-6 w2-7";
}
.calendar > .toolbar { grid-area: toolbar; }
.calendar > .mon { grid-area: mon; }
.calendar > .tue { grid-area: tue; }
.calendar > .wed { grid-area: wed; }
.calendar > .thu { grid-area: thu; }
.calendar > .fri { grid-area: fri; }
.calendar > .sat { grid-area: sat; }
.calendar > .sun { grid-area: sun; }
.calendar > .w1-1 { grid-area: w1-1; }
.calendar > .w1-2 { grid-area: w1-2; }
.calendar > .w1-3 { grid-area: w1-3; }
.calendar > .w1-4 { grid-area: w1-4; }
.calendar > .w1-5 { grid-area: w1-5; }
.calendar > .w1-6 { grid-area: w1-6; }
.calendar > .w1-7 { grid-area: w1-7; }
.calendar > .w2-1 { grid-area: w2-1; }
.calendar > .w2-2 { grid-area: w2-2; }
.calendar > .w2-3 { grid-area: w2-3; }
.calendar > .w2-4 { grid-area: w2-4; }
.calendar > .w2-5 { grid-area: w2-5; }
.calendar > .w2-6 { grid-area: w2-6; }
.calendar > .w2-7 { grid-area: w2-7; }
@media (min-width: 900px) {
.calendar {
grid-template-rows: auto auto minmax(120px, auto) minmax(120px, auto);
gap: 4px;
}
}
How this layout works
Seven equal columns, one row per week: repeat(7, minmax(0, 1fr)). The minmax(0, …) is what stops a long event title from making Wednesday wider than Thursday.
Multi-day events are the reason to use Grid here rather than a table. An event from Tuesday to Thursday is grid-column: 3 / 6 — one element spanning three cells — which a table of day cells cannot express without colspan gymnastics.
Give the day cells a minmax(90px, auto) row so an empty week still looks like a week, and a busy one can grow. Fixed row heights force you to hide events behind a "+3 more" link earlier than you need to.
Every property used here is listed in the CSS Grid cheat sheet, with the reason to reach for it.
Frequently asked questions
How do I build a month calendar with CSS Grid?
minmax(0, 1fr) and one row per week. The minmax(0, …) matters: without it a long event title makes one weekday wider than the rest.How do I show an event that spans several days?
grid-column: 3 / 6. This is the thing a table of day cells cannot do, and the main reason to build a calendar with Grid.How do I center a grid in CSS?
justify-content: center on the grid container to centre the whole grid inside it, and margin-inline: auto with a max-width to centre the container in the page. These are different jobs: the first moves the tracks within the container, the second moves the container itself.How do I center items inside a CSS grid?
place-items: center on the container. That is shorthand for align-items plus justify-items, and it centres every item inside its own cell on both axes. For a single item, use place-self: center on that item instead.How do I make a CSS grid responsive?
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) and it reflows at every width with no media queries at all. Add breakpoints only when the exact column count matters, or when the layout has to change shape rather than just wrap.When should I use CSS Grid instead of Flexbox?
How to use it
-
Open the pattern
The calendar month view loads into the editor already responsive, with every breakpoint set up.
-
Change the tracks
Edit the column and row sizes in the Tracks panel. Anything valid in a track list works.
-
Redraw at another width
Move the ruler past a breakpoint marker and rearrange. Only the placement changes.
-
Copy the code
Take CSS, HTML, Tailwind or a shadcn component. The media queries are already written.
More in App UI
- Responsive Card Grid
- Bento Grid
- Kanban Board
- Chat App Layout
- Email Client Layout
- Settings Page
- Login Page Layout