Understanding Viewport Meta Tags and Device Scaling
The viewport meta tag is your first step toward responsive design. Here’s how to configure it properly for all devices.
Read MoreFlexible grids are the foundation of responsive design. Learn how to use percentages and modern CSS techniques to create layouts that actually adapt instead of break.
Most developers think responsive design means using media queries. They’re not wrong, but that’s only part of the story. The real magic happens when you build your foundation right from the start. We’re talking about flexible grids—the underlying structure that lets your layout breathe.
A flexible grid doesn’t use fixed pixel widths. Instead, it uses percentages, fractions, and calculated values that adapt to whatever viewport you’re working with. When you get this right, your design doesn’t just survive on mobile—it actually thrives.
Here’s the fundamental shift: instead of thinking “this column should be 320 pixels wide,” you think “this column should take up half the available space.” It’s a different mindset entirely. On a 320px phone, half the space is 160px. On a 1440px desktop, it’s 720px. Same proportion, completely different absolute sizes.
The math is straightforward. Take your target width, divide it by your container width, and you’ve got your percentage. A 300px column inside a 960px container? That’s 31.25%. But here’s where it gets practical—you don’t even need to do this manually anymore. CSS Grid and Flexbox handle the proportions for you.
Let’s start with Flexbox since it’s the most straightforward. You’ve got a container that’s 100% of the viewport width. Inside, you want three columns that are equal width. Set the container to display: flex , then give each child flex: 1 . Done. Each column automatically gets one-third of the available space.
The beauty here is that you haven’t specified a single pixel value. When the viewport shrinks, the columns shrink proportionally. When it expands, they expand. At 1200px, your columns might be 400px each. At 600px, they’re 200px each. The relationship stays constant.
Add a gap between columns with gap: 2rem , and Flexbox handles the math. It subtracts the gap from the available space before calculating column widths. You don’t need to manually adjust percentages or margins.
Your flexible grid works great up to a point. But at some screen sizes, you’ll want to change the layout entirely. That’s where media queries come in. You’re not breaking your grid—you’re adapting it for different contexts.
Most projects work well with three breakpoints: mobile at 320px, tablet at 768px, and desktop at 1024px or higher. At mobile, you might stack your three columns into one. At tablet, maybe two columns. At desktop, all three side by side.
Write your base CSS for mobile—single column, full width. This is your foundation.
At 768px, switch to a two-column layout using your flexible grid approach.
At 1024px and above, expand to three or more columns as your design requires.
Once you’ve mastered basic flexible grids, there’s a level deeper. These techniques help you create layouts that feel native to every device you’re supporting.
The clamp() function lets you set minimum, preferred, and maximum values. Your element scales fluidly between those constraints without any media queries. A font size that’s always readable? Use clamp. Column widths that scale with viewport? Same approach.
Container queries let components adapt based on their parent container size, not the viewport. A card doesn’t care if the screen is wide—it cares how much space it actually has. This is a game-changer for component libraries and reusable layouts.
When you’ve got grids within grids, subgrid lets child elements align with the parent grid columns. Your nested components automatically respect the overall layout structure without fighting it.
The aspect-ratio property ensures images and videos maintain their proportions as they scale. No more layout shifts or distorted images when content loads.
Let’s say you’re building a product listing page. On mobile, you want 1 product per row. Tablet? 2 products. Desktop? 4 products across. Your flexible grid makes this elegant.
Set your container to Flexbox with flex-wrap: wrap . Each product card has a flexible width—maybe flex: 0 1 calc(100% – 1rem) on mobile. Add a media query at 768px: flex: 0 1 calc(50% – 1rem) . At 1024px: flex: 0 1 calc(25% – 1.5rem) .
The gap between cards automatically handles spacing. Images inside scale to fit their container. Text wraps naturally. You’ve built a layout that works everywhere without a single hardcoded breakpoint pixel value.
Flexible grids aren’t a trendy technique—they’re the foundation of modern web design. When you understand percentages, proportions, and how Flexbox distributes space, you stop fighting your layouts and start working with them.
The best part? You don’t need to memorize formulas or write complex media query chains. Modern CSS does the heavy lifting. You just need to think in proportions instead of pixels, and your layouts will adapt to any screen size naturally.
Flexible grids are just the beginning. Learn media queries, viewport settings, and mobile-first thinking to create complete responsive experiences.
Explore More GuidesThis article is intended for educational purposes. While the techniques and approaches discussed are based on established CSS standards and best practices, actual implementation may vary depending on your specific project requirements, target browsers, and business goals. Always test your responsive layouts across multiple devices and browsers. For production applications, consider consulting with experienced web developers or UX specialists to ensure your implementation meets your users’ needs.