mediumFrontend EngineerDesign
How do you implement responsive design patterns — mobile-first, container queries, and fluid typography?
Posted 18/04/2026
by Mehedy Hasan Ador
Question Details
At a design agency:
> "Our site looks different on every device. Media queries aren't enough because components need to respond to their container size, not viewport. How do we handle this?"
> "Our site looks different on every device. Media queries aren't enough because components need to respond to their container size, not viewport. How do we handle this?"
Suggested Solution
Mobile-First Approach
/* Base: Mobile styles */
.card {
display: flex;
flex-direction: column;
padding: 16px;
}
/* Tablet+ */
@media (min-width: 768px) {
.card {
flex-direction: row;
padding: 24px;
}
}
/* Desktop+ */
@media (min-width: 1024px) {
.card {
padding: 32px;
max-width: 1200px;
}
}
Container Queries (Modern CSS)
/* Define containment context */
.sidebar {
container-type: inline-size;
container-name: sidebar;
}
/* Respond to CONTAINER size, not viewport */
@container sidebar (min-width: 400px) {
.card {
flex-direction: row; /* Horizontal when sidebar is wide */
}
}
@container sidebar (max-width: 399px) {
.card {
flex-direction: column; /* Vertical when sidebar is narrow */
}
}
Fluid Typography (clamp)
/* Old: fixed breakpoints */
h1 { font-size: 24px; }
@media (min-width: 768px) { h1 { font-size: 48px; } }
/* New: fluid — scales smoothly between breakpoints */
h1 {
font-size: clamp(1.5rem, 1rem + 2.5vw, 3rem);
/* min: 1.5rem, preferred: 1rem + 2.5vw, max: 3rem */
}
/* Fluid spacing */
.section {
padding: clamp(1rem, 0.5rem + 2vw, 3rem);
}
Responsive Patterns Summary
clamp()min()/max()aspect-ratiodvh (dynamic vh)