Back to Blog

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:

/ Width-based (most common) /
@media (min-width: 768px) { }
@media (max-width: 767px) { }

/ Range /
@media (min-width: 768px) and (max-width: 1023px) { }

/ Orientation /
@media (orientation: portrait) { }
@media (orientation: landscape) { }

/ Prefer reduced motion (accessibility) /
@media (prefers-reduced-motion: reduce) {
* {
animation: none !important;
transition: none !important;
}
}

/ Dark mode preference /
@media (prefers-color-scheme: dark) {
body {
background: #1a1a1a;
color: #f0f0f0;
}
}

Common Breakpoints

/ Mobile: 0 - 767px (default styles) /

/ Tablet: 768px - 1023px /
@media (min-width: 768px) { }

/ Desktop: 1024px - 1279px /
@media (min-width: 1024px) { }

/ Large Desktop: 1280px+ /
@media (min-width: 1280px) { }

Flexible Units

Relative Units

/ rem - relative to root font size (usually 16px) /
.heading {
font-size: 2rem; / 32px /
margin-bottom: 1rem; / 16px /
}

/ em - relative to parent font size /
.card-title {
font-size: 1.5em;
}

/ Viewport units /
.hero {
height: 100vh; / Full viewport height /
width: 100vw; / Full viewport width /
}

/ Percentages /
.sidebar {
width: 30%;
}

The clamp() Function

Create fluid typography without media queries:

.heading {
/ Minimum, preferred, maximum /
font-size: clamp(1.5rem, 4vw, 3rem);
}

.container {
width: clamp(300px, 90%, 1200px);
}

Flexible Images

Make images responsive:

img {
max-width: 100%;
height: auto;
}

For background images:

.hero {
background-image: url('hero.jpg');
background-size: cover;
background-position: center;
}

Responsive Images in HTML


srcset="small.jpg 480w,
medium.jpg 768w,
large.jpg 1200w"
sizes="(max-width: 480px) 480px,
(max-width: 768px) 768px,
1200px"
src="large.jpg"
alt="Responsive image"
>





Adaptive image

Responsive Patterns

Responsive Navigation


.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
}

.nav-links {
display: none;
flex-direction: column;
position: absolute;
top: 60px;
left: 0;
right: 0;
background: white;
}

.nav-links.active {
display: flex;
}

.menu-toggle {
display: block;
}

@media (min-width: 768px) {
.nav-links {
display: flex;
flex-direction: row;
position: static;
background: none;
}

.menu-toggle {
display: none;
}
}

Responsive Grid

.grid {
display: grid;
gap: 20px;
grid-template-columns: 1fr; / Mobile: 1 column /
}

@media (min-width: 768px) {
.grid {
grid-template-columns: repeat(2, 1fr); / Tablet: 2 columns /
}
}

@media (min-width: 1024px) {
.grid {
grid-template-columns: repeat(3, 1fr); / Desktop: 3 columns /
}
}

Or use auto-fit for automatic responsiveness:

.grid {
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

Testing Responsive Design

In ProLiveEditor

Use the Desktop/Mobile toggle to test your responsive designs:

  • Write your CSS with mobile-first styles
  • Add media queries for larger screens
  • Toggle between views to see the results

Browser DevTools

  • Open DevTools (F12)
  • Click the device toolbar icon
  • Select different device presets or set custom dimensions

Complete Responsive Page Example

Try this in ProLiveEditor:



My Responsive Site



Card 1

Card 2

Card 3


© 2025 My Site


* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

.page {
min-height: 100vh;
display: flex;
flex-direction: column;
}

.header {
padding: 20px;
background: #3498db;
color: white;
text-align: center;
}

.main {
flex: 1;
padding: 20px;
display: grid;
gap: 20px;
grid-template-columns: 1fr;
}

.card {
background: #f9f9f9;
padding: 30px;
border-radius: 8px;
text-align: center;
}

.footer {
padding: 20px;
background: #34495e;
color: white;
text-align: center;
}

@media (min-width: 768px) {
.main {
grid-template-columns: repeat(2, 1fr);
}
}

@media (min-width: 1024px) {
.main {
grid-template-columns: repeat(3, 1fr);
max-width: 1200px;
margin: 0 auto;
}
}

Practice building responsive layouts in ProLiveEditor — toggle between Desktop and Mobile views to test your designs!

Try the Examples

Practice what you've learned with ProLiveEditor's live code editor.

Open Editor
PE
ProLiveEditor Team Building tools to help developers learn and create.