CSS Grid can reproduce both common header/footer behaviours: a persistent footer that stays pinned to the bottom of the viewport while the main content scrolls in its own box, and the classic "sticky" footer that hugs the bottom edge when content is short but is pushed down once content grows. Neither approach needs fixed heights, hard-coded paddings, margins or line breaks.

The markup is a single #app element inside <body>, containing <header>, <main> and <footer>. The demo uses React purely to switch between chunks of markup; nothing in the CSS depends on it. Sections render in a <section> child with fake content: a Billing view that spans the full width and a Settings view that sits in a centred strip.

The starting grid is one column — 1fr, meaning "take the remaining space", here the full container width — and three rows:

#app {
  /* etc. */
  grid-template-rows: auto 1fr auto;
  /* etc. */
}

Header and footer rows are auto, so they size to their content. The middle row is 1fr, absorbing whatever space the other two leave. Because the grid spans the full viewport height, one section must grow into unused space, which is the main row's job.

With that in place, the Settings content overflows and the whole page scrolls, carrying the header away and pushing the footer out of view.

The fix is a single declaration: overflow: auto on <main>. The main element then scrolls internally while header and footer hold their positions. This is the "truly fixed" footer variant — a persistent footer rather than the pushed-down kind. The trade-off worth noting on fixed-position implementations of the same pattern (Charles Schwab's homepage, for instance) is that they rely on fixed positioning and therefore hard-coded dimensions: a fixed footer size, 15px bottom padding on the <footer>, 20px margins on a footer <ul>, and even line breaks, all to prevent main content from hiding behind the footer.

#app > main {
  grid-area: main;
  overflow: auto;
  padding: 15px 5px 10px 5px;
}

A centred main column via a nested grid

To let <main> either span the viewport or sit in a centred 600px strip, make <main> a grid container — a grid inside a grid. Its three column tracks are 1fr 600px 1fr: 600px in the middle, remaining space split evenly on either side. A fixed width with auto margins would achieve the same visual result, but it breaks down later.

#app > main {
  display: grid;
  grid-template-rows: 1fr;
  grid-template-columns: 1fr 600px 1fr;
}

Each module's <section> sits in the middle column by default and spans all three columns when it carries a .full class. Coordinates use the explicit form [row-start] / [col-start] / [row-end] / [col-end]:

#app > section {
  grid-area: 1 / 2 / 1 / 3;
}


#app > section.full {
  grid-area: 1 / 1 / 1 / 4
}

The col-end of 4 reflects grid lines, not columns: four lines bound three columns. So the default sits between lines 2 and 3, and .full spans lines 1 through 4.

One flaw remains: below 600px of display width the content is abruptly truncated, because the centre track is fixed. The minmax() function supplies a minimum and a maximum and lets the grid compute a value in between, which prevents the content from blowing out of the grid. Replacing the fixed value with minmax(0, 600px) makes the centre track act as a width of up to 600px.

main {
  display: grid;
  grid-template-rows: 1fr;
  grid-template-columns: 1fr minmax(0, 600px) 1fr;
}

The scroll-inside-main behaviour can be traded for the classic sticky footer without discarding the work. The structural change is to move <footer> into <main>, so the element that scrolls is also the element containing the footer. #app shrinks from three rows to two — header and everything else:

#app {
  /* same as before */


  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: 
    'header'
    'main';
}

Main's nested grid gains lines: one row for the <section> sized 1fr, and an auto row for the footer. The footer is then positioned in that grid rather than in #app:

#app > main {
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: 1fr minmax(0, 600px) 1fr;
}

This yields a footer that rests at the bottom of the screen when content is short and scrolls with the content when it exceeds the viewport.

Fine-tuning the scrollable section

Two adjustments follow from moving the footer. <main> cannot have left or right padding, or the footer will no longer reach edge to edge. The <section> that handles adjustable width gets display: flex, a width of 100%, and overflow: auto on its immediate child div. This lets the section's content scroll horizontally within itself when it exceeds the column boundary, while preventing vertical scrolling. The flex container forces the child div to fill the available vertical space, and the child's overflow: auto enables the scrolling. Setting overflow-x to auto with overflow-y to visible is not a viable alternative; that combination does not work.

Why bother using Grid at all

None of this is new capability. The 600px centre column could be a block element with max-width: 600px and auto side margins. The fixed footer could use position: fixed, provided the main content does not overlap it. The sticky footer has various pre-Grid solutions. The argument for Grid is uniformity: a single layout mechanism covers all of it. Moving the footer from fixed to sticky, once the grid rows exist, reduces to rearranging items across rows, while headers and footers sized with auto rows need no hard-coded dimensions at all.

body {
  margin: 0;
}


#app {
  height: 100vh;
  
  /* grid container settings */
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: 
    'header'
    'main'
    'footer';
}


#app > header {
  grid-area: header;
}


#app > main {
  grid-area: main;
  padding: 15px 5px 10px 5px;
}


#app > footer {
  grid-area: footer;
}