📱 Responsive Design Course

🎯 Learning Objectives

After completing this course, you will be able to:

⚡ Prerequisites

  • HTML & CSS Course completed
  • Understanding of Flexbox and Grid
  • Basic CSS knowledge
  • Multiple devices for testing (optional)

1. Viewport Configuration

The Viewport Meta Tag

This is the most important tag for responsive design:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

What it does:

⚠️ Common Viewport Mistakes

2. Mobile-First Approach

Why Mobile-First?

  • Most users browse on mobile devices
  • Forces focus on essential content
  • Better performance on mobile
  • Easier to scale up than down
  • Progressive enhancement

Mobile-First Workflow

  1. Design for smallest screen first
  2. Add complexity for larger screens
  3. Use min-width media queries
  4. Test on real devices

Mobile-First CSS Example

/* Base styles for mobile (no media query needed) */ .container { width: 100%; padding: 15px; } .card { margin-bottom: 20px; } /* Tablet and up (min-width: 768px) */ @media screen and (min-width: 768px) { .container { max-width: 750px; margin: 0 auto; padding: 20px; } .card { display: inline-block; width: 48%; margin-right: 2%; } } /* Desktop and up (min-width: 1024px) */ @media screen and (min-width: 1024px) { .container { max-width: 1000px; } .card { width: 31%; } }

3. Media Queries

Media Query Syntax

/* Basic syntax */ @media media-type and (condition) { /* CSS rules */ } /* Common examples */ @media screen and (min-width: 768px) { /* Styles for screens 768px and wider */ } @media screen and (max-width: 767px) { /* Styles for screens up to 767px */ } @media screen and (min-width: 768px) and (max-width: 1023px) { /* Styles for screens between 768px and 1023px */ } /* Orientation */ @media screen and (orientation: landscape) { /* Landscape mode styles */ } @media screen and (orientation: portrait) { /* Portrait mode styles */ } /* Print styles */ @media print { .no-print { display: none; } }

Common Breakpoints

  • Mobile: 320px - 767px
  • Tablet: 768px - 1023px
  • Desktop: 1024px - 1199px
  • Large Desktop: 1200px+

Device-Specific Queries

/* iPhone */ @media screen and (min-width: 375px) and (max-width: 812px) { /* iPhone styles */ } /* iPad */ @media screen and (min-width: 768px) and (max-width: 1024px) { /* iPad styles */ }

4. Fluid Layouts

Percentage-Based Layouts

/* Fluid container */ .container { width: 90%; max-width: 1200px; margin: 0 auto; } /* Fluid columns */ .column { float: left; width: 100%; padding: 15px; } @media screen and (min-width: 768px) { .column { width: 50%; } } @media screen and (min-width: 1024px) { .column { width: 33.333%; } }

Modern Responsive Grid

/* Auto-responsive grid - no media queries needed! */ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; padding: 20px; } /* Flexbox responsive layout */ .flex-container { display: flex; flex-wrap: wrap; gap: 20px; } .flex-item { flex: 1 1 300px; /* grow shrink basis */ min-width: 0; /* Prevent overflow */ }
Box 1
Box 2
Box 3
Box 4

Resize your browser to see the responsive grid in action!

5. Responsive Images

Basic Responsive Images

/* Make all images responsive */ img { max-width: 100%; height: auto; display: block; } /* Responsive background images */ .hero { background-image: url('hero-mobile.jpg'); background-size: cover; background-position: center; height: 300px; } @media screen and (min-width: 768px) { .hero { background-image: url('hero-tablet.jpg'); height: 400px; } } @media screen and (min-width: 1024px) { .hero { background-image: url('hero-desktop.jpg'); height: 500px; } }

Picture Element for Art Direction

<picture> <!-- Desktop image --> <source media="(min-width: 1024px)" srcset="image-large.jpg"> <!-- Tablet image --> <source media="(min-width: 768px)" srcset="image-medium.jpg"> <!-- Mobile image (default) --> <img src="image-small.jpg" alt="Responsive image"> </picture> <!-- With WebP support --> <picture> <source type="image/webp" srcset="image.webp"> <source type="image/jpeg" srcset="image.jpg"> <img src="image.jpg" alt="Modern image format"> </picture>

6. Responsive Typography

Fluid Typography with clamp()

/* Modern approach using clamp() */ h1 { font-size: clamp(1.5rem, 5vw, 3rem); /* min: 1.5rem, preferred: 5vw, max: 3rem */ } h2 { font-size: clamp(1.25rem, 4vw, 2rem); } p { font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.6; } /* Responsive line length */ .content { max-width: 65ch; /* 65 characters wide */ margin: 0 auto; }

Traditional Responsive Typography

/* Base mobile typography */ body { font-size: 16px; line-height: 1.5; } h1 { font-size: 1.75rem; } /* Tablet */ @media screen and (min-width: 768px) { body { font-size: 18px; } h1 { font-size: 2.5rem; } } /* Desktop */ @media screen and (min-width: 1024px) { body { font-size: 20px; } h1 { font-size: 3rem; } }

7. Breakpoints Strategy

Content-Based Breakpoints

Add breakpoints where your content breaks, not at specific device sizes:

  1. Start with mobile design
  2. Expand browser width
  3. Add breakpoint when layout breaks
  4. Repeat for larger sizes

Common Breakpoint Values

/* Small devices */ @media (min-width: 576px) { } /* Medium devices */ @media (min-width: 768px) { } /* Large devices */ @media (min-width: 992px) { } /* Extra large devices */ @media (min-width: 1200px) { } /* Extra extra large */ @media (min-width: 1400px) { }

💡 Best Practices

Practice Exercises

📝 Exercise 1: Mobile-First Navigation (3 points)

Create a responsive navigation that:

📝 Exercise 2: Responsive Card Grid (3 points)

Create a card grid that displays:

📝 Exercise 3: Responsive Hero Section (4 points)

Create a hero section with:

🎉 Summary

You've completed the Responsive Design course! You now know:

Total points available: 10/10