HTML Responsive Design

Pages that look good on every screen.

✍️ 3 exercises + code challenge in this lesson

Responsive web design makes a page adapt to phones, tablets and desktops.

Key techniques

  1. Add the viewport meta tag: <meta name="viewport" content="width=device-width, initial-scale=1.0">.
  2. Make images flexible with max-width: 100%; height: auto;.
  3. Use relative units like %, rem and vw.
  4. Use media queries to change the layout at certain widths.
Press Layout in the editor or resize your browser to watch the boxes rearrange.

Key Takeaways: HTML Responsive Design

Mastering HTML Responsive Design helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML Responsive Design Code Example

HTML
<style>
  img { max-width: 100%; height: auto; border-radius: 8px; }
  .grid { display: flex; flex-wrap: wrap; gap: 10px; }
  .box  { flex: 1 1 30%; background: #2563EB; color: white; padding: 20px; border-radius: 8px; }
  @media (max-width: 500px) {
    .box { flex-basis: 100%; background: #14B8A6; }
  }
</style>

<img src="https://picsum.photos/id/1018/900/300" alt="Mountains">
<div class="grid">
  <div class="box">Box 1</div>
  <div class="box">Box 2</div>
  <div class="box">Box 3</div>
</div>
Free sign-in required · Google login available

HTML Responsive Design Practice Exercises

Check what you learned in “HTML Responsive Design”.

/ 3 solved
Fill in the blank

Make images shrink on small screens.

img {
  : 100%;
  height: auto;
}
✓ Correct! Not quite. Try again.
Multiple choice

Which CSS feature applies styles only at certain screen widths?

✓ Correct! Not quite. Try again.
Code challenge

Add CSS so the image has max-width: 100%.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services