4 min read · Free · No login needed
Responsive design means one website that looks good on every screen — a phone, a tablet, a laptop, a TV. Today more than half of all web traffic comes from phones, so a page that only works on a desktop is a page that loses half its visitors.
Add <meta name="viewport" content="width=device-width, initial-scale=1.0"> to the head. Without it, phones pretend to be 980 pixels wide and shrink your page to fit — everything becomes tiny.
Set images to max-width: 100%; height: auto; in CSS. The image then shrinks to fit a narrow screen instead of overflowing and forcing a sideways scroll. Never use a fixed pixel width on an image that must work on phones.
A media query applies CSS only when the screen is a certain size. For example: @media (max-width: 600px) { .sidebar { display: none; } } hides the sidebar on phones, where there is no room for it. You write the desktop layout first, then add queries that adjust it for smaller screens — or the other way round, starting mobile-first.
Resize your browser window to check the layout, but also open the page on a real phone. Touch targets (buttons, links) need to be big enough for a finger — at least 44 pixels tall — and text must stay readable without pinching to zoom.
Responsive means the page adapts to the screen it is shown on. The same page should be readable on a 27-inch monitor, a laptop, a tablet, and a small phone — without the visitor having to zoom or scroll sideways. The layout stretches, shrinks, and rearranges itself, and images scale down to fit.
Two pieces of code do most of the work. First, the viewport tag in the head. Second, a media query in CSS — a rule that only applies when the screen is a certain size:
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
img { max-width: 100%; height: auto; }
/* On screens narrower than 600px, stack the columns */
@media (max-width: 600px) {
.row { flex-direction: column; }
}
</style>
The max-width: 100% rule stops images from overflowing their container, and height: auto keeps them from stretching out of shape.
width: 1200px — on a 360px phone, the page overflows and scrolls sideways.max-width: 100% so it can shrink.<meta name="viewport" ...> — the first step of responsive design. It tells phones to show the page at their real width.img { max-width: 100%; height: auto; } — the image can shrink to fit a narrow screen, and height: auto keeps it from stretching out of shape.@media (max-width: 600px) — a media query: an "if" for screen size. The rules inside it only apply when the screen is narrower than 600 pixels..sidebar { display: none; } — inside that media query, the sidebar is hidden on phones, where there is no room for it.<img src="photo.jpg" alt="..."> — the photo itself. On a phone it shrinks to fit; on a desktop it shows at full size.<!DOCTYPE html>
<html>
<head>
<title>Responsive</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
img { max-width: 100%; height: auto; }
@media (max-width: 600px) {
.sidebar { display: none; }
}
</style>
</head>
<body>
<h1>Responsive Page</h1>
<img src="photo.jpg" alt="A photo that shrinks on small screens">
<div class="sidebar">Sidebar — hidden on phones.</div>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
One website that looks good on every screen, from a phone and tablet to a laptop and TV, without zooming or sideways scrolling.
Without it, phones pretend to be 980 pixels wide and shrink the page so everything becomes tiny.
It applies CSS only when the screen is a certain size, for example hiding the sidebar on screens narrower than 600 pixels.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →