Aral Code

Page Structure Lesson 29 of 42

Responsive Web Design Basics — Pages That Fit Every Screen

Make your HTML pages work on phones, tablets and computers using the viewport meta tag, flexible images, relative units and media queries.

A responsive website changes its layout to fit the screen it's on — a narrow phone, a tablet, or a wide laptop. In the Philippines, most people go online using a phone, so if your page only looks good on a computer, it fails for most of your visitors. The good news: making a page responsive takes only a few habits.

Habit 1: always include the viewport meta tag

<meta name="viewport" content="width=device-width, initial-scale=1">

This single line tells the phone, "use your real screen width, don't zoom out." Without it, none of the other techniques work properly on phones.

Habit 2: make images flexible

An image with width="800" is wider than most phone screens (about 360–430 pixels wide), so it sticks out and forces sideways scrolling. Fix it with CSS:

Example Images that shrink to fit
<style>
  img { max-width: 100%; height: auto; }
</style>
<p>Resize this preview (or open on a phone) — the picture never overflows.</p>
<img src="/img/jeepney.svg" alt="A red jeepney" width="800" height="500">
  • max-width: 100% — the image can shrink to fit its container but never grows bigger than its real size.
  • height: auto — keeps the proportions, so it doesn't look stretched.

Put this rule in every website you make. It's one of the most useful lines of CSS you'll ever write.

Habit 3: avoid fixed widths

A box with width: 900px will never fit on a phone. Use percentages or max-width instead:

<style>
  /* Bad: always 900px, too wide for phones */
  .content { width: 900px; }

  /* Good: up to 900px on big screens, full width on small ones */
  .content { max-width: 900px; width: 100%; margin: 0 auto; }
</style>

margin: 0 auto centers the box on wide screens.

Habit 4: use relative font sizes

Instead of fixed pixel sizes everywhere, many developers use rem units. 1rem equals the browser's base font size (usually 16px), so 1.5rem is 24px. If a user sets a bigger text size on their phone for easier reading, rem sizes grow with it.

<style>
  body { font-size: 1rem; line-height: 1.6; }
  h1 { font-size: 2rem; }
</style>

Habit 5: media queries

A media query applies CSS only when a condition is true, such as "the screen is narrower than 600 pixels." This lets you change the layout for phones.

Example Cards in a row on wide screens, stacked on phones
<style>
  .cards { display: flex; gap: 12px; }
  .card { flex: 1; background: #e3f1ec; padding: 14px; border-radius: 10px; font-family: Arial, sans-serif; }
  @media (max-width: 600px) {
    .cards { flex-direction: column; }
  }
</style>
<div class="cards">
  <div class="card"><h3>STEM</h3><p>Science, Technology, Engineering and Mathematics</p></div>
  <div class="card"><h3>ABM</h3><p>Accountancy, Business and Management</p></div>
  <div class="card"><h3>ICT</h3><p>Information and Communications Technology</p></div>
</div>

On a computer the three cards sit side by side. Make the preview narrow (or view on a phone) and they stack. Try changing 600px to 900px to see when the switch happens.

Mobile-first

Many developers write the phone styles first, then add min-width media queries for bigger screens. It keeps phone pages lighter and simpler:

<style>
  /* Phone (default) */
  .cards { display: flex; flex-direction: column; gap: 12px; }

  /* Tablets and computers */
  @media (min-width: 700px) {
    .cards { flex-direction: row; }
  }
</style>

Habit 6: make things easy to tap

A mouse pointer is tiny; a fingertip is not. Links and buttons that are too small or too close together cause wrong taps. Give buttons and menu links enough padding — a good target is at least about 44 × 44 pixels.

Habit 7: handle wide tables

Tables with many columns can't shrink much. Wrap them in a container that scrolls sideways so the rest of the page stays in place:

<div style="overflow-x: auto;">
  <table>...</table>
</div>

How to test your page

  • On a real phone. The best test. Upload your page or use VS Code's Live Server on the same Wi-Fi.
  • Browser developer tools. In Chrome on a computer, press F12, then click the phone/tablet icon (Toggle device toolbar). You can pick screen sizes like iPhone or Galaxy.
  • Resize the window. Drag your browser window narrower and watch the layout adjust.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What CSS makes images shrink to fit small screens?
2. What does @media (max-width: 600px) { ... } do?
3. Why is .box { width: 900px; } a problem?
4. What is a quick way to test phone layouts in Chrome on a computer?

By Sir Reyel · Last updated 2026-12-04