Understanding the concept of responsive web design, its importance in today's digital landscape, and how it ensures optimal user experience across different devices.
Introduction to Responsive Web Design (RWD)
| Principle | Description | Typical Techniques |
|---|---|---|
| Fluid Grids | Layout dimensions expressed in relative units (percentages, fr in CSS Grid) rather than fixed pixels. |
CSS Grid, Flexbox, width: 100% |
| Flexible Images & Media | Media scales with its container, preventing overflow. | max-width: 100%; height: auto;, object-fit, picture element, srcset |
| Media Queries | CSS rules that apply only when certain conditions (viewport width, resolution, orientation) are met. | @media (min-width: 768px) { … } |
| Mobile‑First Strategy | Start styling for the smallest screens, then progressively enhance for larger viewports. | Base styles → @media (min-width: …) overrides |
| Touch‑Friendly UI | Controls sized for finger taps; adequate spacing between interactive elements. | Minimum touch target: ~44 × 44 dp, larger hit areas, CSS :active feedback |
/* Example: 3‑column layout that collapses on small screens */
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
}
auto-fit / auto-fill + minmax() creates columns that expand/contract automatically./* Breakpoints (customizable) */
@media (min-width: 576px) { /* small tablets */ }
@media (min-width: 768px) { /* portrait tablets */ }
@media (min-width: 992px) { /* small laptops */ }
@media (min-width: 1200px) { /* desktops */ }
<picture>
<source srcset="hero-large.webp 1200w,
hero-medium.webp 800w"
media="(min-width: 800px)" type="image/webp">
<img src="hero-fallback.jpg"
srcset="hero-small.jpg 400w,
hero-medium.jpg 800w"
sizes="(max-width: 600px) 100vw,
50vw"
alt="Hero image">
</picture>
srcset + sizes let the browser pick the most appropriate file..nav {
display: flex;
flex-wrap: wrap; /* items wrap on narrow screens */
justify-content: space-between;
}
.nav a { flex: 1 1 120px; } /* minimum width, grow as needed */
| Device Category | Approx. Width | Typical Breakpoint |
|---|---|---|
| Phones (portrait) | ≤ 480 px | — (base mobile‑first styles) |
| Phones (landscape) |