Responsive Web Design: Building Sites That Work Everywhere
Learn the fundamentals of responsive web design. Create websites that look great on desktops, tablets, and mobile phones.
CSSResponsive DesignMobile-First
Responsive Web Design: Building Sites That Work Everywhere
Responsive web design (RWD) ensures your website looks great and functions well on any device — from large desktop monitors to small smartphone screens. In this guide, we'll cover the essential techniques for building responsive websites.
The Foundation: Viewport Meta Tag
Always include this meta tag in your HTML:
This tells browsers to:
Set the viewport width to the device width
Set the initial zoom level to 100%
Without this, mobile browsers will render the page as if it were a desktop site and scale it down.
Mobile-First Design
Mobile-first means designing for small screens first, then adding styles for larger screens:
/ Base styles (mobile) / .container { padding: 15px; }
.card { width: 100%; margin-bottom: 15px; }
/ Tablet and up / @media (min-width: 768px) { .container { padding: 30px; }
.card { width: 48%; } }
/ Desktop and up / @media (min-width: 1024px) { .container { padding: 50px; max-width: 1200px; margin: 0 auto; }
.card { width: 32%; } }
Why Mobile-First?
Performance — Mobile devices receive only the CSS they need
Progressive enhancement — Core functionality works everywhere
Cleaner code — Start simple, add complexity as needed
Media Queries
Media queries apply styles based on device characteristics: