DevPath · Learn to code ESPTEN

Responsive design

Fluid units and elements

Stop thinking in fixed pixels

A truly responsive design doesn't only jump between breakpoints: it also flows between them. A card with width: 400px is always 400 px, whether it fits or not; one with width: 90% molds to whatever space it has. That's why we use relative units instead of fixed px:

.column {
  width: 90%;          /* flows with the container */
  max-width: 60rem;    /* but doesn't grow without limit */
  margin: 0 auto;      /* centered */
}

Fluid images

An image with a width larger than its container causes horizontal scroll. The golden rule is to make it fluid:

img {
  max-width: 100%;   /* never wider than its container */
  height: auto;      /* keeps the proportion */
}

max-width: 100% lets the image shrink on small screens but not stretch beyond its natural size. It's the basis of responsive media.

Fluid typography with clamp()

Jumping the font size between breakpoints works, but clamp() lets it flow continuously between a minimum and a maximum:

h1 {
  font-size: clamp(1.5rem, 4vw, 3rem);
}

clamp(MINIMUM, IDEAL, MAXIMUM) reads like this:

Result: a heading that adapts on its own, without a single media query.

Combine with flex and grid

Fluid units shine alongside Flexbox and Grid, which already distribute the available space. A very powerful pattern for responsive galleries without media queries:

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

auto-fit + minmax creates as many columns as fit, each at least 220 px and sharing the rest (1fr). On mobile you'll see one column; as it gets wider, two, three, four appear… without you writing a single breakpoint. The layout reorganizes itself. This is expert-level responsive: let the layout engine decide instead of hard-coding each breakpoint by hand.

And that closes the loop: viewport to enable responsiveness, mobile-first to build from less to more, media queries for the big jumps and fluid units for everything else. One website, every screen. 🚀

Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
← Media queries and breakpointsView the module →