SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 28 of 35

HTML Responsive Design: Viewport, Images & Media Queries

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.

Diagram — see how it fits together
Infographic: responsive design on desktop and phone

Step 1: the viewport tag

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.

Step 2: flexible images

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.

Step 3: media queries

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.

Test on a real phone

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.

Tip: In Chrome, press F12 and click the phone icon (top-left of the developer panel) to see your page as a phone would show it, in many screen sizes.

What responsive means

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.

Syntax

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.

Note: A media query is just an "if" for screen size: "if the screen is narrower than 600 pixels, use these rules instead". You can have several breakpoints — for example, one at 900px for tablets and one at 600px for phones.
Tip: Design for the phone first, then add rules for bigger screens. This is called mobile-first design, and it keeps your CSS shorter — most visitors today arrive on a phone.

Common mistakes

  • Forgetting the viewport tag — without it, phones show the desktop layout shrunk tiny.
  • Setting fixed pixel widths on containers, like width: 1200px — on a 360px phone, the page overflows and scrolls sideways.
  • Using a large image with a fixed width — use max-width: 100% so it can shrink.
  • Testing only on a desktop — shrink the browser window, and check the page on a real phone before you publish.

Example explained

  • <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.

Example

Example
<!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>

Output

Output — how it looks in the browser
Output of HTML Responsive Design: Viewport, Images & Media Queries

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is responsive design?

One website that looks good on every screen, from a phone and tablet to a laptop and TV, without zooming or sideways scrolling.

2. Why is the viewport tag needed for responsive pages?

Without it, phones pretend to be 980 pixels wide and shrink the page so everything becomes tiny.

3. What does a media query do?

It applies CSS only when the screen is a certain size, for example hiding the sidebar on screens narrower than 600 pixels.

Why learn this yourself — and not just ask AI?

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.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Website Design & Development Workshop 2026
₹299
View
Master Python + AI Skills in 30 Days
₹499
View
CapCut Mobile Video Editing Course Beginner to Advance
₹99
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →