Fluid Layouts and Responsive Images: Relative Units, max-width, clamp(), min(), max(), picture, srcset and object-fit

HTML5 and CSS3 55 min min read Updated: Nov 17, 2026 Intermediate
Fluid Layouts and Responsive Images: Relative Units, max-width, clamp(), min(), max(), picture, srcset and object-fit
Intermediate Topic 2 of 3

Fluid Means Flexible

Instead of fixed pixel widths that break on small screens, use flexible sizes that stretch and shrink.

css .container { width: 100%; max-width: 70rem; margin-inline: auto; padding-inline: 1rem; } img, video { max-width: 100%; height: auto; }

max-width: 100% stops an image from being wider than its parent. height: auto keeps its shape.

min(), max() and clamp()

FunctionMeaning
min(a, b)The smaller value
max(a, b)The larger value
clamp(min, ideal, max)The ideal value, but never below min or above max
css .wide { width: min(100% - 2rem, 70rem); margin-inline: auto; } h1 { font-size: clamp(1.5rem, 1rem + 2.5vw, 3rem); } .section { padding-block: clamp(2rem, 6vw, 5rem); }
Measured in Chrome

h1 font size at 400px wide: 26px h1 font size at 700px wide: 33.5px h1 font size at 1000px wide: 41px

The heading grows smoothly with the screen: 1rem + 2.5vw is 16 + 10 = 26px at 400px wide. It stays between 24px (1.5rem) and 48px (3rem). No media query is needed.

Accessibility Keep a rem part in the middle value, like 1rem + 2.5vw. Pure vw text does not grow when people zoom or change their text size.

srcset and sizes

html <img src="img/cat-800.jpg" srcset="img/cat-400.jpg 400w, img/cat-800.jpg 800w, img/cat-1600.jpg 1600w" sizes="(min-width: 900px) 33vw, 100vw" alt="A cat sitting on a sofa" width="800" height="600" loading="lazy">
  • Create several sizes of each photo
  • srcset lists the files and their real widths
  • sizes says how wide the image will show on the page
  • The browser picks the smallest file that still looks sharp, which saves data on phones

Art Direction with picture

html <picture> <source media="(min-width: 800px)" srcset="img/hero-wide.jpg"> <img src="img/hero-square.jpg" alt="Team at work" width="600" height="600"> </picture>

Use picture when you want a different crop on different screens, such as a wide image for desktops and a tight square one for phones.

Keep the Shape: aspect-ratio and object-fit

css .thumb { aspect-ratio: 16 / 9; width: 100%; object-fit: cover; border-radius: .5rem; } .video-box { aspect-ratio: 16 / 9; width: 320px; }
Measured in Chrome

a 320px wide box with aspect-ratio 16 / 9 has a height of: 180

Reserve space An aspect-ratio or width and height attributes stop the page from jumping when images load.

Practice

  1. Make a heading that scales with clamp
  2. Add three image sizes with srcset and check the downloaded file in the Network tab
  3. Make equal looking thumbnails from photos of different shapes

Conclusion

Fluid layouts use relative sizes, max-width, clamp and flexible images. Serve smaller files to small screens.

Quick Summary: Fluid idea; min, max, clamp; srcset; picture; aspect-ratio and object-fit.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators