Master CSS From Scratch

Clear, interactive, and structured CSS lessons designed for beginners.

Responsive Web Design

Responsive Web Design is a web development approach in which a website adapts its layout, content, images, and other elements according to the screen size and device.

A responsive website should provide a consistent and usable experience on desktop computers, tablets, and mobile devices.

What is Responsive Web Design?

Responsive Web Design means building a website that can automatically adjust to different screen sizes.

The same website can change its layout without requiring a separate desktop and mobile version.

Responsive Web Design Diagram

Desktop
Header
Main
Sidebar
Tablet
Header
Main
Sidebar
Mobile
Header
Main
Sidebar

The layout adapts to the available screen size.

Responsive Layout

A responsive layout uses flexible CSS techniques so that elements can resize or rearrange when the available screen space changes.

.container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
    }
}

On larger screens, the layout contains two columns.

The first column uses 2fr and the second column uses 1fr.

When the screen width becomes 768px or smaller, the layout changes to one column.

Flexible Widths

Percentage values can be used to create flexible widths that adjust according to the parent container.

.container {
    width: 80%;
}

.content {
    width: 60%;
}

The container takes 80% of the available width.

The content element takes 60% of its parent width.

Responsive Grid

.cards {
    display: grid;
    grid-template-columns:
        repeat(3, 1fr);
    gap: 20px;
}

@media (max-width: 768px) {
    .cards {
        grid-template-columns: 1fr;
    }
}

Three equal columns are displayed on larger screens.

At 768px or below, the cards are displayed in a single column.

Responsive Images

Images should be able to shrink according to the width of their parent container.

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

max-width: 100%; prevents the image from becoming wider than its parent container.

height: auto; maintains the image's original aspect ratio.

Responsive Typography

Text should remain readable on different screen sizes.

h1 {
    font-size: 40px;
}

@media (max-width: 768px) {
    h1 {
        font-size: 28px;
    }
}

On larger screens, the heading size is 40px.

On screens up to 768px, the heading size becomes 28px.

Responsive Navigation

Navigation menus may also need to change their arrangement on smaller screens.

.navigation {
    display: flex;
    gap: 20px;
}

@media (max-width: 768px) {
    .navigation {
        flex-direction: column;
        gap: 10px;
    }
}

On larger screens, navigation items are placed horizontally.

On smaller screens, they are arranged vertically.

Output

Header
Main Content
Sidebar

On smaller screens, the main content and sidebar can move into a single-column layout.

Important Responsive Web Design Techniques

Flexible Layout

Use flexible widths and layouts that can adapt to available space.

Responsive Grid

Use CSS Grid to rearrange content according to screen size.

Responsive Images

Allow images to scale within their parent containers.

Media Queries

Apply different CSS rules at different screen widths.

Flexible Typography

Adjust text sizes to maintain readability on different devices.

Mobile Layout

Rearrange content so that it remains usable on smaller screens.

Real-World Uses

  • Business websites
  • E-commerce websites
  • Training institute websites
  • Portfolio websites
  • Blogs and news websites
  • Web applications
Important: Responsive Web Design combines flexible layouts, CSS Grid, Flexbox, media queries, responsive images, and appropriate typography to make a website usable across different screen sizes.

Summary

Responsive Web Design allows a website to adapt its layout and content to different devices and screen sizes. Flexible layouts, responsive Grid systems, media queries, responsive images, typography, and navigation techniques help create websites that remain usable across desktops, tablets, and mobile devices.