RWD Intro
RWD Intro
Responsive Web Design (RWD) is a way of building websites that adapt to different screen sizes and devices. A responsive page should work well on phones, tablets, laptops, and large monitors.
RWD is usually built with three core ideas:
- Fluid layout (flexible widths)
- Media queries (breakpoint rules)
- Responsive images/videos (media scales correctly)
RWD Viewport
To make responsive layouts work properly on mobile, you must set the viewport meta tag. Without it, many mobile browsers render the page as a “desktop width” and scale it down.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
This tells the browser to match the page width to the device width and start at a normal zoom level.
RWD Grid View
A responsive grid layout means the page is arranged in columns that can change based on screen width.
Modern CSS Grid example (auto-fit + minmax):
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 14px;
}
Flexbox alternative (wrap + flexible basis):
.row {
display: flex;
flex-wrap: wrap;
gap: 14px;
}
.row .card {
flex: 1 1 240px;
}
Tip: Prefer CSS Grid for 2D page layouts and card grids. Use Flexbox for 1D alignment (rows/columns like navbars).
RWD Media Queries
Media queries apply styles only when conditions match (usually screen width). A common approach is mobile-first: write default styles for small screens, then expand with min-width.
.container {
padding: 12px;
}
@media (min-width: 768px) {
.container { padding: 18px; }
}
@media (min-width: 992px) {
.container { padding: 24px; }
}
Responsive layout example:
.layout {
display: grid;
grid-template-columns: 1fr;
gap: 14px;
}
@media (min-width: 992px) {
.layout {
grid-template-columns: 280px 1fr;
}
}
RWD Images
Responsive images should never overflow their container. The most common rule:
img {
max-width: 100%;
height: auto;
display: block;
}
For fixed-size thumbnails/cards, use object-fit:
.thumb img {
width: 100%;
height: 220px;
object-fit: cover;
object-position: center;
}
RWD Videos
Videos and iframes (like YouTube embeds) often need an aspect-ratio wrapper to stay responsive.
Modern approach (aspect-ratio):
.video {
width: 100%;
aspect-ratio: 16 / 9;
}
.video iframe,
.video video {
width: 100%;
height: 100%;
display: block;
}
Fallback wrapper technique:
.video-wrap {
position: relative;
padding-top: 56.25%; /* 16:9 */
}
.video-wrap iframe {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
RWD Frameworks
Responsive frameworks provide ready-to-use grid systems and components. Many projects use frameworks to move faster and keep layouts consistent.
- Bootstrap – responsive grid and UI components
- Tailwind – utility classes with responsive breakpoints
Tip: Even with a framework, it helps to understand the core RWD principles (viewport, flexible layout, media queries).
RWD Templates
RWD templates are pre-built responsive layouts (for example: blog layout, landing page, admin layout). They typically include:
- responsive header + navigation
- grid-based content area
- responsive images
- breakpoints for tablet/desktop
Simple template layout idea (sidebar becomes stacked on mobile):
.page {
display: grid;
grid-template-columns: 1fr;
gap: 14px;
}
@media (min-width: 992px) {
.page {
grid-template-columns: 280px 1fr;
}
}
Summary
- RWD adapts layouts to different screens using viewport, flexible grids, and media queries.
- Use the viewport meta tag for correct mobile scaling.
- Make images and videos responsive with simple CSS patterns.
- Frameworks and templates can speed up development, but the fundamentals still matter.