You’ve been there. You load a site on your phone and—bam!—there’s a full-width image blowing past the viewport like it’s trying to escape. Or worse, a video crammed so tightly it looks like it’s being punished for existing. These moments are the result of media that didn’t get the responsive memo.
If you’re building for all devices (and let’s face it, you are), making sure your images and videos behave is just as important as your layout.

What Makes Media “Flexible”?
Flexible media are visual elements—images, videos, iframes—that adjust themselves based on the size of their container or the screen they’re being viewed on. No cut-off corners, no overflow scrollbars. Just visuals that stretch, shrink, and shift gracefully.
The Core CSS Rule That Keeps Images in Line
img { max-width: 100%; height: auto; }
This simple combo keeps images from overflowing their container while preserving their aspect ratio. No stretching. No squishing. Just a clean, proportional resize.
Smarter Image Delivery: Responsive Techniques That Matter
Scaling is one thing. Delivering the right image is another. That’s where srcset
and the <picture>
element come in. These let the browser pick the best image source based on screen size or resolution, saving bandwidth and speeding up load times.
Example Using <picture>
:
<picture> <source media="(max-width: 600px)" srcset="image-small.jpg"> <source media="(min-width: 601px)" srcset="image-large.jpg"> <img src="fallback.jpg" alt="Example image"> </picture>
Mobile users get a smaller file. Desktop users get more details. Everyone wins.
Embedding Responsibly: Videos and Iframes That Adapt
Static widths and heights don’t cut it for videos anymore. A responsive video setup uses a container with a clever padding hack to maintain aspect ratio and full responsiveness.
Responsive Video Container (CSS):
.video-container { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; overflow: hidden; } .video-container iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
Drop this around YouTube or Vimeo embeds and you’re golden. Libraries like FitVids.js can help automate this if you’re dealing with a content-heavy site.
Don’t Just Flex: Optimize
Responsive media isn’t just about resizing—it’s about performance, too. A few golden rules:
- Compress your images (hello, WebP)
- Lazy-load non-critical visuals with
loading="lazy"
- Use a CDN to serve assets faster across regions
These tweaks make your site snappier and more respectful of users’ data plans.
Wrapping It Up
Flexible media practices are the difference between a site that just looks “fine” and one that feels effortless on every device. They protect your layout, keep your users engaged, and show that you care about performance just as much as polish.
Let me know if you’d like a downloadable checklist or a sandbox demo to go with this article.