← All articles

CSS

Responsive CSS layouts

Build fluid layouts with Grid, flexible sizing and sensible breakpoints.

On this page

  1. Use flexible containers
  2. Let Grid do the work
  3. Test content, not devices

Use flexible containers

Avoid a fixed width for the entire document. Set a maximum width and allow the container to shrink with the viewport.

Let Grid do the work

Auto-fit creates as many tracks as the available space permits. A minimum track width capped at 100% prevents overflowing very narrow screens.

Test content, not devices

Resize the viewport continuously. Check long words, large text, narrow windows and landscape orientation before adding breakpoints.

Example

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}

Related reading