agyanadda@gmail.com

HTML Responsive Design

HTML Best Practices 1 min read Updated Nov 30, 2026 Topic 31 of 33

Most visitors in India use phones, so every page must work on small screens.

The three basics

  1. Viewport tag in the head: <meta name="viewport" content="width=device-width, initial-scale=1">.
  2. Flexible images: img { max-width: 100%; height: auto; } so images never overflow.
  3. Media queries in CSS to change the layout on small screens.

Responsive images

srcset lets the browser pick a smaller image for phones — faster loading and less data.

Example

Example — Responsive basics HTML
<style>
  img { max-width: 100%; height: auto; }
  .cards { display: flex; gap: 10px; }
  .card { flex: 1; background: #e0f2fe; padding: 12px; }
  @media (max-width: 600px) {
    .cards { flex-direction: column; }
  }
</style>

<div class="cards">
  <div class="card">Card 1</div>
  <div class="card">Card 2</div>
  <div class="card">Card 3</div>
</div>
<p>Make the window narrow — the cards stack on top of each other.</p>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which CSS rule stops images from overflowing the screen?

Exercise 2 True / False

Without the viewport meta tag, mobile phones show a tiny zoomed-out page.

Frequently Asked Questions

In Chrome press F12 and click the phone icon (Device Toolbar) to preview different screen sizes.