A responsive page works on small and large screens. HTML provides the structure, and CSS adapts it. Use this checklist when you build a page.
The checklist
- Viewport tag in the head, see The Viewport.
- Flexible images:
max-width: 100%; height: auto;, withsrcsetfor large images, see Responsive Images. - Fluid layout: use percentages,
flexorgridinstead of fixed pixel widths. - Readable text: at least 16 pixels for body text and comfortable line length, around 60 to 80 characters.
- Touch-friendly controls: buttons and links about 44 pixels high, with space between them.
- Tables that scroll instead of breaking the page, see Styling Tables.
- Source order: put the most important content first in the HTML, so it comes first on small screens too.
A simple responsive layout
<style>
* { box-sizing: border-box; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card { background: #f8f2ee; padding: 12px; border-radius: 8px; }
</style>
<div class="cards">
<div class="card">Fiction</div>
<div class="card">Poetry</div>
<div class="card">Travel</div>
<div class="card">Cooking</div>
</div>
Drag the browser window narrower and the cards wrap on their own.
Media queries
When a layout needs a bigger change, use a media query:
@media (min-width: 700px) {
.layout { display: grid; grid-template-columns: 1fr 3fr; }
}