A responsive page adapts to every screen size.
Building blocks
- Viewport meta tag in the HTML head
- Fluid widths —
%,max-width,frinstead of fixed pixels - Flexible images —
img { max-width: 100%; height: auto; } - Flexible layouts — Flexbox
flex-wrapand Gridauto-fit - Fluid text —
font-size: clamp(1.5rem, 4vw, 3rem); - 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>