agyanadda@gmail.com

CSS Responsive Design

Responsive CSS and Best Practices 1 min read Updated Dec 1, 2026 Topic 38 of 39

A responsive page adapts to every screen size.

Building blocks

  1. Viewport meta tag in the HTML head
  2. Fluid widths — %, max-width, fr instead of fixed pixels
  3. Flexible images — img { max-width: 100%; height: auto; }
  4. Flexible layouts — Flexbox flex-wrap and Grid auto-fit
  5. Fluid text — font-size: clamp(1.5rem, 4vw, 3rem);
  6. Media queries for bigger changes

Test it

Use DevTools device mode (Ctrl+Shift+M) to preview phones and tablets.

Example

Example — Responsive hero section HTML
<style>
  * { box-sizing: border-box; }
  .hero { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; padding: 20px; background: #f0f6ff; border-radius: 10px; }
  .hero .text { flex: 1 1 260px; }
  .hero h1 { font-size: clamp(1.5rem, 5vw, 2.8rem); color: #1f386b; margin: 0 0 8px; }
  .hero .img { flex: 1 1 200px; height: 160px; background: linear-gradient(135deg, #4a90e2, #1f386b); border-radius: 10px; }
  .btn { display: inline-block; background: #e8590c; color: white; padding: 10px 20px; border-radius: 6px; text-decoration: none; }
</style>

<section class="hero">
  <div class="text">
    <h1>Learn CSS Today</h1>
    <p>Free lessons with live examples.</p>
    <a class="btn" href="#">Start now</a>
  </div>
  <div class="img"></div>
</section>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which CSS keeps images inside their container?

Exercise 2 Fill in the Blank

The ___() function sets a font size with a minimum, preferred and maximum value.

Exercise 3 True / False

Responsive design needs a separate website for mobile.

Frequently Asked Questions

Designing for small screens first and adding styles for larger screens with min-width media queries. It keeps CSS simpler and pages faster on phones.