Score code, devs, and debt fast.

Start free trial
HTML

HTML

HTML Responsive Web Design

Responsive Web Design (RWD) builds web pages that adjust to all screen sizes, from desktop monitors to mobile phones. In this tutorial you will learn core techniques that create fluid, accessible, and fast layouts. All examples use HTML and CSS and work in any modern browser.

Learning Outcomes

After this tutorial, you will:

  • Describe core principles of Responsive Web Design.
  • Configure the viewport with a <meta> tag.
  • Make images responsive using CSS and srcset/picture.
  • Scale text fluidly with clamp().
  • Write media queries for breakpoints.
  • Build layouts with Flexbox, Grid, and multi‑column.
  • Use W3.CSS and Bootstrap grids.

What is Responsive Web Design?

Responsive Web Design is an approach in which a single set of HTML files serves tailored layouts through CSS and the browser’s rendering engine. Instead of shipping separate “m.”, “mobile.” or “tablet.” sites or subdomains, you:

  1. Fluidly scale content (text, images, video) to fit the viewport.
  2. Apply breakpoints with media queries so complex layouts re‑flow gracefully.
  3. Optimise performance with device‑appropriate assets.

Benefits include lower maintenance, better SEO (Google favours mobile‑friendly pages, user behavioral metrics are consolidated), and greater accessibility.

Setting the Viewport with the <meta> Tag

The viewport is the portion of the document the browser uses to lay out and scale content. Declare it once, on every page:

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
  • width=device-width tells the browser to match the visual viewport’s width.
  • initial-scale=1.0 sets a 1‑to‑1 zoom level on first load.

Attribute Reference

Attribute What It Controls Typical Value
width Virtual viewport width device-width or integer px
height Virtual viewport height † ‑‑
initial-scale Initial zoom factor 1.0
minimum-scale Smallest zoom the user can reach 0.5, 1.0
maximum-scale Largest zoom the user can reach 3.0, 5.0
user-scalable Allow pinch‑zoom? yes / no
interactive-widget How virtual keyboards affect viewport ‡ resizes-visual

† Rarely needed; most browsers ignore it.

‡ Draft spec; supported in Chromium‑based browsers.

Responsive Images

Modern pages should never force users to pan or zoom just to view an image.

Fill‑Container Scaling (width: 100%)

When you set width: 100%, the image always fills the full width of its parent container. That means it grows or shrinks in lock‑step with the element around it, even stretching beyond its intrinsic pixel dimensions on very wide screens. While this guarantees zero horizontal scrolling, it can introduce blurriness if the image is enlarged beyond its original resolution.

<img src="/assets/sitepoint-logo.svg" style="width: 100%;" alt="SitePoint logo">

Intrinsic Scaling (max-width: 100%)

Using max-width: 100% keeps the image responsive without ever exceeding its natural size. If the parent container is narrower than the image, the graphic scales down; if the container is wider, the image caps at its intrinsic width, preserving sharpness. Pairing this with height: auto maintains the correct aspect ratio as the browser adjusts the width.

<img src="/assets/sitepoint-logo.svg"
     style="max-width: 100%; height: auto;" alt="SitePoint logo">

Different Images Depending on Browser Width

Sometimes you don’t just want a single image that scales—you want the browser to pick the most appropriate file for its current viewport. HTML offers two complementary ways to do that:

Technique When to Use How It Works
srcset + sizes on <img> Same composition, multiple resolutions (e.g., 600 px, 900 px, 1200 px) Browser chooses the smallest file whose width ≥ the slot size derived from the sizes list.
<picture> element Completely different crops or art‑directed images Browser evaluates each child <source> in order and downloads the first whose media query matches.

Example — Resolution Switching with srcset

<img
  src="/img/hero-600.jpg"
  srcset="/img/hero-600.jpg 600w,
          /img/hero-900.jpg 900w,
          /img/hero-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw,
         (max-width: 1024px) 50vw,
         33vw"
  alt="Mountain view at sunrise">
  1. srcset lists candidate files followed by their intrinsic widths.
  2. sizes tells the browser how wide the slot will be at various breakpoints:
    • Up to 600 px viewport ➜ slot ≈ 100 % of viewport (100vw).
    • 601–1024 px ➜ slot ≈ 50 % of viewport.
    • Anything larger ➜ slot ≈ 33 % of viewport.
  3. The browser multiplies the slot width by its device‑pixel‑ratio and selects the smallest file that will look crisp.

Using these attributes keeps bandwidth low on tiny screens while delivering retina‑sharp assets to high‑DPI laptops—all without a single JavaScript callback or extra HTTP round‑trip.

Responsive Text Size

Fluid typography keeps reading comfortable on any screen. One line of CSS does the magic:

h1 { font-size: clamp(1.6rem, 5vw + 1rem, 3.4rem); }
  • Clamp sets a minimum, preferred, and maximum size.
  • The middle value (5vw + 1rem) scales with the viewport but respects the bounds.

Media Queries — Your Layout’s Breakpoints

In addition to scaling text and images, responsive pages often use media queries to swap entire style blocks for different screen sizes. With a single @media rule you can create layouts that flow horizontally on large monitors yet stack vertically on small phones.

Try it: resize the browser window and watch the three cards drop from a row to a column.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Media Query Demo</title>
<style>
  /* Mobile‑first baseline (phones) */
  .cards            { display: flex; flex-direction: column; gap: 1rem; }
  .card             { flex: 1 1 100%; padding: 2rem; background: #f3f5fa; border-radius: .5rem; }

  /* 768 px and up (tablets & desktops) */
  @media (min-width: 48rem) {
    .cards          { flex-direction: row; }
  }
</style>
</head>
<body>
  <section class="cards">
    <article class="card">Card 1</article>
    <article class="card">Card 2</article>
    <article class="card">Card 3</article>
  </section>
</body>
</html>

Common query targets you’ll reach for:

  • Screen width / heightmin-width, max-width
  • Orientationorientation: landscape
  • Pointer accuracypointer: coarse
  • User preferencesprefers‑reduced‑motion, prefers‑color‑scheme

Media queries let you tailor experiences precisely, keeping your design intuitive on every device.

Building Responsive Layouts

Modern CSS offers three core layout engines—Flexbox, Grid, and Multi‑Column—each suited to a different sizing problem. Pick the one that matches your content flow rather than forcing everything into a single system.

Flexbox

Use Flexbox when items need to line up in a row or a column and wrap naturally as space allows—perfect for menus, pricing tiles, and nav bars.

<section class="pricing">
  <article class="plan">Free</article>
  <article class="plan">Pro</article>
  <article class="plan">Enterprise</article>
</section>
.pricing { display: flex; flex-wrap: wrap; gap: 1rem; }
.plan    { flex: 1 1 18rem; }   /* grow, shrink, min‑width 18 rem */

CSS Grid

Grid excels at magazine‑style layouts where both rows and columns need explicit control—image galleries, dashboards, and complex forms.

.gallery {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

auto-fit packs in as many columns as will fit; minmax() prevents them from collapsing.

Multi‑Column Layout

Multi‑column is ideal for long, text‑heavy articles on ultra‑wide screens, letting the browser reflow paragraphs into newspaper‑style columns.

.article-body {
  column-width: 20rem;   /* target width per column        */
  column-gap:   2rem;    /* space between columns          */
}

Responsive Design Frameworks

Frameworks bundle ready‑made grids and utilities so you can prototype quickly—handy for landing pages or MVPs when time matters more than byte‑perfection.

W3.CSS Quick Start

A tiny, vanilla‑CSS framework with mobile‑first classes—no JavaScript, minimal footprint.

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<div class="w3-row-padding">
  <div class="w3-third"></div>
  <div class="w3-third"></div>
  <div class="w3-third"></div>
</div>

Bootstrap 5 Grid

The industry standard 12‑column system plus thousands of utility classes—great for teams that value convention and component depth.

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
  <div class="row">
    <div class="col-12 col-md-4">One</div>
    <div class="col-12 col-md-4">Two</div>
    <div class="col-12 col-md-4">Three</div>
  </div>
</div>

Bootstrap’s power comes with extra CSS; use a build tool or purge step to remove unused styles in production.

FAQs on HTML Responsive Web Design

How do I make my site fully responsive?

  1. Use flexible units (%, rem, vw).
  2. Add <meta name="viewport" content="width=device-width, initial-scale=1">.
  3. Set images and videos to max-width: 100%.
  4. Add breakpoints where the layout fails.
  5. Test in browser DevTools and on real devices.

Does HTML adapt to screen size by default?

No. HTML alone stacks content vertically. You need CSS (viewport tag, grid or flex, media queries) to adjust layout to different screens.

How do I build a responsive drop‑down menu?

  1. Wrap a list in a <nav> element.
  2. Use Flexbox for desktop layout.
  3. Add a script to toggle a hamburger button on mobile.
  4. Apply an @media (min-width: 48rem) rule for larger screens.

What steps create a responsive web page in HTML?

  1. Structure your document with HTML5 tags: <header>, <nav>, <main>, <aside>, <footer>.
  2. Apply responsive CSS: grid or flex layouts, fluid typography.
  3. Enhance with JavaScript: lazy‑load assets and toggle menus.
  4. Optimize images and run a Lighthouse audit.
Subscribe to our newsletter

Get the freshest news and resources for developers, designers and digital creators in your inbox each week

© 2000 – 2025 SitePoint Pty. Ltd.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.