Course

Web Development
  • 1.1 Introduction to the Web
  • 2.1 HTML Basics
  • 2.2 Text & Content
  • 2.3 Layout & Grouping
  • 2.4 Lists & Tables
  • 2.5 Media & Embedding
  • 2.6 Forms
  • 2.7 Semantic HTML
  • 2.8 Accessibility & SEO
  • 3.1 CSS Introduction
  • 3.2 CSS Syntax
  • 3.3 CSS Selectors
  • 3.4 Typography
  • 3.5 Colors & Backgrounds
  • 3.6 Text Styling
  • 3.7 Box Model
  • 3.8 Units
  • 3.9 Display & Positioning
  • 3.10 Layout Systems
  • 3.11 Responsive Design
  • 3.12 Animations
  • 3.13 Modern CSS
  • 3.14 Performance & Accessibility
  • 3.15 Tailwind CSS Basics
  • 4.1 Introduction to JavaScript
  • 4.2 Variables & Scope
  • 4.3 Data Types
  • 4.4 Type Conversion
  • 4.5 Operators
  • 4.6 Control Flow
  • 4.7 Loops
  • 4.8 Functions
  • 4.9 Advanced Functions
  • 4.10 Objects & Arrays
  • 4.11 The this Keyword

3.11 Responsive Design

Updated Jul 12, 2026

3.11 Responsive Design

Updated Jul 12, 2026

Responsive Design

Responsive Design is the practice of building websites that automatically adapt to different screen sizes and devices.

A responsive website works well on:

  • Desktop
  • Laptop
  • Tablet
  • Mobile Phone
  • Smart TV

Instead of creating separate websites, responsive design allows a single website to adjust its layout automatically.


What is Responsive Design?

Responsive Design ensures that:

  • Content remains readable
  • Layout adapts to screen size
  • Images scale correctly
  • Navigation stays usable
  • User experience remains consistent

Example:

Desktop

+---------------------------+
| Sidebar | Main Content    |
+---------------------------+

Mobile

+-------------------+
| Main Content      |
+-------------------+
| Sidebar           |
+-------------------+

The same website uses a different layout depending on the device.


Why Responsive Design Matters

Most users browse websites on mobile devices.

Responsive websites provide:

  • Better User Experience
  • Better Accessibility
  • Better SEO
  • Easier Maintenance
  • Higher Conversion Rates

Responsive Design Principles

Flexible Layouts

Avoid fixed widths.

Instead of:

width: 1200px;

Use:

width: 100%;
max-width: 1200px;

Flexible Images

Avoid fixed image sizes.

Bad:

img {
    width: 800px;
}

Good:

img {

    max-width: 100%;

    height: auto;

}

Images automatically scale without overflowing their container.


Relative Units

Instead of fixed pixel values:

font-size: 32px;

Use scalable units such as:

font-size: 2rem;

or

font-size: clamp(1rem, 4vw, 3rem);

Media Queries

Media Queries apply different styles based on the screen size.

Syntax:

@media (condition) {

    selector {

        property: value;

    }

}

Example:

@media (max-width: 768px) {

    body {

        background: lightblue;

    }

}

The styles are applied only when the screen width is 768px or smaller.

Desktop example:

@media (min-width: 1024px) {

    body {

        background: white;

    }

}

Common Breakpoints

Device Breakpoint
Mobile @media (max-width: 576px)
Tablet @media (max-width: 768px)
Laptop @media (max-width: 1024px)
Desktop @media (min-width: 1200px)

Responsive Navigation

Desktop:

.nav {

    display: flex;

}

Mobile:

@media (max-width: 768px) {

    .nav {

        flex-direction: column;

    }

}

Desktop:

Home About Contact

Mobile:

Home
About
Contact

Responsive Grid

Desktop:

.grid {

    display: grid;

    grid-template-columns:
    repeat(3, 1fr);

}

Mobile:

@media (max-width: 768px) {

    .grid {

        grid-template-columns:
        1fr;

    }

}

The layout changes from three columns to one column.


Multiple Media Queries

/* Mobile */

@media (max-width: 576px) {

}

/* Tablet */

@media (min-width: 577px)
and
(max-width: 768px) {

}

/* Desktop */

@media (min-width: 769px) {

}

Media Query Operators

Both conditions:

@media
(min-width: 768px)
and
(max-width: 1024px)

Either condition:

@media
(max-width: 576px),
(min-width: 1200px)

Container Queries

Container Queries style elements based on the size of their parent container instead of the viewport.

Enable container queries:

.card-wrapper {

    container-type: inline-size;

}

Example:

@container
(max-width: 500px) {

    .card {

        flex-direction: column;

    }

}

The layout changes only when the container becomes smaller than 500px.


Media Queries vs Container Queries

Media Queries Container Queries
Viewport based Container based
Layout level Component level
Traditional approach Modern approach

Responsive Typography

Responsive typography keeps text readable on every screen size.

Instead of:

font-size: 60px;

Use scalable units:

font-size: 3rem;

Viewport units:

font-size: 5vw;

Or the recommended approach:

font-size:

clamp(
    2rem,
    5vw,
    4rem
);

This sets:

  • Minimum size
  • Responsive scaling
  • Maximum size

Typography Scale

h1 {

    font-size:
    clamp(2.5rem, 6vw, 5rem);

}

h2 {

    font-size:
    clamp(2rem, 4vw, 3rem);

}

h3 {

    font-size:
    clamp(1.5rem, 3vw, 2rem);

}

p {

    font-size:
    clamp(1rem, 2vw, 1.2rem);

}

Complete Example

.container {

    width: 100%;

    max-width: 1200px;

    margin: auto;

}

.grid {

    display: grid;

    grid-template-columns:
    repeat(3, 1fr);

    gap: 20px;

}

@media (max-width: 768px) {

    .grid {

        grid-template-columns:
        1fr;

    }

}

h1 {

    font-size:

    clamp(
        2rem,
        5vw,
        4rem
    );

}

Best Practices

  • Use Flexbox and Grid for layouts.
  • Use relative units such as rem, %, vw, and vh.
  • Use clamp() for responsive typography.
  • Make images responsive using:
img {

    max-width: 100%;

    height: auto;

}
  • Follow a mobile-first approach.

Example:

.card {

    width: 100%;

}

@media (min-width: 768px) {

    .card {

        width: 50%;

    }

}

Key Takeaway

Responsive design allows websites to work on every device.

Modern responsive development commonly uses:

display: flex;

display: grid;

width: 100%;

font-size:

clamp(
    1rem,
    4vw,
    3rem
);

@media (max-width: 768px) {

}

A modern responsive website is built using:

  • Flexbox
  • CSS Grid
  • Media Queries
  • Container Queries
  • Responsive Typography
  • Mobile-First Design
3.10 Layout Systems3.12 Animations