CHAPTER 45 · HTML
Small-screen pages: flexible content and a simple media query
Keep one useful page readable at different widths. Connect viewport settings with flexible images, sensible text and a small CSS layout change.
Download example files (ZIP)The same notice in a narrow notebook
Begin with the viewport setting
Let paragraphs and images fit
Read the small sizing rules
A media query asks a conditional question
@media (min-width: 48rem) {
.practice-steps {
grid-template-columns: 1fr 1fr;
}
}Read the grid example without guessing
Test between the neat screenshots
What this chapter does not claim
Follow the idea
- 1Start with a readable column
- 2Let text and images fit
- 3Apply a query when space allows
- 4Test widths, zoom and reading order
A viewport tag starts the setup; flexible content and real checks complete it.
Complete program: flexible-notice.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A Flexible Practice Notice</title>
<style>
body {
margin: 1rem;
color: #202c3a;
font-family: Arial, sans-serif;
line-height: 1.6;
}
main {
max-width: 44rem;
margin: 0 auto;
}
img {
max-width: 100%;
height: auto;
}
.practice-address {
overflow-wrap: anywhere;
}
</style>
</head>
<body>
<h1>A notice that fits its space</h1>
<main>
<p>Keep the words readable instead of shrinking the whole page.</p>
<img
src="images/study-desk.svg"
alt="An open notebook beside a laptop on a study desk"
width="360"
height="220"
/>
<p class="practice-address">
Practice identifier: notebook-workshop-room-B204-afternoon-preparation-checklist-2027
</p>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Complete program: responsive-cards.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Practice Cards for Different Widths</title>
<style>
body {
margin: 1rem;
color: #202c3a;
font-family: Arial, sans-serif;
line-height: 1.6;
}
main {
max-width: 44rem;
margin: 0 auto;
}
img {
max-width: 100%;
height: auto;
}
.practice-address {
overflow-wrap: anywhere;
}
.practice-steps {
display: grid;
gap: 1rem;
}
.practice-steps section {
min-width: 0;
border: 1px solid #7990aa;
padding: 1rem;
}
@media (min-width: 48rem) {
.practice-steps {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<h1>Two steps for your next practice</h1>
<main>
<p>The same two steps stay in the same reading order at every width.</p>
<div class="practice-steps">
<section>
<h2>Prepare a file</h2>
<p>Save a short page and give it a clear filename.</p>
</section>
<section>
<h2>Explain the result</h2>
<p>Open the page, test one change and describe what happened.</p>
</section>
</div>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Problem and solution
Common mistakes and useful tips
Viewport metadata does not repair every fixed width. Keep image proportions when resizing. Do not use spaces or line breaks to fake columns. Choose breakpoints for content rather than brand-name devices. Keep the same logical reading order. Check several widths and preserve zoom.
Practice questions
What does responsive design aim to do? Does max-width:100% choose a smaller image file? Why use height:auto with a resized image? When does the example have two columns? Does a two-column layout change the source order? Save both programs and test a narrow and wide window. Look for side scrolling and compare reading order.
Check your practice answers
Keep a page useful at different available sizes and conditions. No. It limits displayed size. Resource selection is a separate job. To preserve its proportions. When its layout viewport matches min-width:48rem. No. The two sections remain in their original order. Content should fit normally, long identifiers can wrap, and the second program changes columns only at its query threshold while preserving the same content.
Interview questions
Is a responsive page a separate mobile copy?
How do viewport metadata and media queries differ?
Why is one screenshot insufficient?
Why avoid hiding important content on phones?
Quick revision
Begin with a readable single column. Combine viewport metadata and flexible content. Use media queries for content-driven changes. Test widths, wrapping, reading order and zoom.