Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 03 · Semantic Architecture & SEOChapter 18 of 18
17.
Phase 03Read time ~21 minDifficulty beginner

Responsive HTML

Modern websites must work across many screen sizes:

In this chapter
  • 01What Is Responsive Web Design?
  • 02Responsive HTML vs Responsive CSS
  • 03The Viewport
  • 04Why width=device-width Matters
  • 05Mobile-First Thinking
  • 06Why Mobile-First?
  • 07HTML Should Not Be Duplicated Unnecessarily
  • 08Responsive Images
  • 09srcset
  • 10What Does 480w Mean?
  • 11Why src Is Still Included
  • 12sizes
  • 13Understanding sizes
  • 14What Is vw?
  • 15How Browser Chooses an Image
  • 16Responsive Image Example
  • 17Why width and height Still Matter
  • 18Responsive Image ≠ CSS width: 100%
  • 19<picture>
  • 20Why Use <picture>?
  • 21Art direction
  • 22srcset vs <picture>
  • 23Modern Image Formats
  • 24Responsive Video
  • 25Responsive YouTube Iframe
  • 26Responsive Tables
  • 27Don't Destroy Table Semantics
  • 28Responsive Forms
  • 29Don't Use HTML Tables for Form Layout
  • 30Touch-Friendly Controls
  • 31Don't Rely on Hover
  • 32Responsive Navigation
  • 33Responsive Layout Structure
  • 34HTML Should Follow Content Priority
  • 35CSS Grid and Responsive HTML
  • 36CSS Flexbox
  • 37Media Queries
  • 38Hiding vs Reorganizing
  • 39Responsive Typography
  • 40Avoid Hardcoded Widths
  • 41The max-width Pattern
  • 42Responsive HTML and Accessibility
  • 43Responsive Images + Accessibility
  • 44Responsive <picture> + Accessibility
  • 45Responsive HTML for High-Density Displays
  • 46srcset Width vs Density Descriptors
  • 47Width descriptors
  • 48Pixel-density descriptors
  • 49Responsive Backgrounds vs HTML Images
  • 50Responsive Decorative Images
  • 51Responsive Embedded Content
  • 52Orientation
  • 53Responsive Content Strategy
  • 54What is essential?
  • 55What can move?
  • 56What can be deferred?
  • 57What should never disappear?
  • 58A Production Responsive Page
  • 59Common Responsive Mistakes
  • 60Mistake 1 — Fixed width
  • 61Mistake 2 — Huge images everywhere
  • 62Mistake 3 — Duplicate mobile and desktop HTML
  • 63Mistake 4 — Hiding important content
  • 64Mistake 5 — Tiny touch targets
  • 65Mistake 6 — Hover-only interaction
  • 66Mistake 7 — Desktop-first thinking everywhere
  • 67Responsive HTML Cheat Sheet
  • 68Responsive Design Mental Model
  • 69Interview Questions
  • 70Q1. What is responsive web design?
  • 71Q2. Why do we use the viewport meta tag?
  • 72Q3. What is srcset?
  • 73Q4. What is sizes?
  • 74Q5. What is <picture>?
  • 75Q6. Difference between srcset and <picture>?
  • 76Q7. Why should images have width and height?
  • 77Q8. How do you make an iframe responsive?
  • 78Q9. Should you create separate HTML for mobile and desktop?
  • 79Q10. Why is mobile-first useful?
  • 80Mini Project — Responsive NextGen Blog
  • 81Next Chapter
  • 82Chapter 17 — Modern HTML APIs
In this chapter (82 sections)
01What Is Responsive Web Design?02Responsive HTML vs Responsive CSS03The Viewport04Why width=device-width Matters05Mobile-First Thinking06Why Mobile-First?07HTML Should Not Be Duplicated Unnecessarily08Responsive Images09srcset10What Does 480w Mean?11Why src Is Still Included12sizes13Understanding sizes14What Is vw?15How Browser Chooses an Image16Responsive Image Example17Why width and height Still Matter18Responsive Image ≠ CSS width: 100%19<picture>20Why Use <picture>?21Art direction22srcset vs <picture>23Modern Image Formats24Responsive Video25Responsive YouTube Iframe26Responsive Tables27Don't Destroy Table Semantics28Responsive Forms29Don't Use HTML Tables for Form Layout30Touch-Friendly Controls31Don't Rely on Hover32Responsive Navigation33Responsive Layout Structure34HTML Should Follow Content Priority35CSS Grid and Responsive HTML36CSS Flexbox37Media Queries38Hiding vs Reorganizing39Responsive Typography40Avoid Hardcoded Widths41The max-width Pattern42Responsive HTML and Accessibility43Responsive Images + Accessibility44Responsive <picture> + Accessibility45Responsive HTML for High-Density Displays46srcset Width vs Density Descriptors47Width descriptors48Pixel-density descriptors49Responsive Backgrounds vs HTML Images50Responsive Decorative Images51Responsive Embedded Content52Orientation53Responsive Content Strategy54What is essential?55What can move?56What can be deferred?57What should never disappear?58A Production Responsive Page59Common Responsive Mistakes60Mistake 1 — Fixed width61Mistake 2 — Huge images everywhere62Mistake 3 — Duplicate mobile and desktop HTML63Mistake 4 — Hiding important content64Mistake 5 — Tiny touch targets65Mistake 6 — Hover-only interaction66Mistake 7 — Desktop-first thinking everywhere67Responsive HTML Cheat Sheet68Responsive Design Mental Model69Interview Questions70Q1. What is responsive web design?71Q2. Why do we use the viewport meta tag?72Q3. What is srcset?73Q4. What is sizes?74Q5. What is <picture>?75Q6. Difference between srcset and <picture>?76Q7. Why should images have width and height?77Q8. How do you make an iframe responsive?78Q9. Should you create separate HTML for mobile and desktop?79Q10. Why is mobile-first useful?80Mini Project — Responsive NextGen Blog81Next Chapter82Chapter 17 — Modern HTML APIs
Desktop       Laptop       Tablet       Mobile
1920px        1440px       768px        390px
  ↓              ↓            ↓            ↓
┌────────┐   ┌────────┐   ┌───────┐   ┌────┐
│        │   │        │   │       │   │    │
│        │   │        │   │       │   │    │
└────────┘   └────────┘   └───────┘   └────┘

Responsive design means the webpage can adapt to the available space and device characteristics instead of assuming one fixed screen size.

HTML plays a major role in this.

CSS performs much of the visual adaptation, but HTML provides the correct structure, responsive resources, semantics, and content relationships.


1. What Is Responsive Web Design?#

Responsive web design means creating websites that adapt to different:

  • Screen widths
  • Screen heights
  • Orientations
  • Input methods
  • Pixel densities
  • Device capabilities

For example:

Desktop
┌────────────────────────────────────────────┐
│ Logo   Home  Products  Blog       Search  │
├────────────────────────────────────────────┤
│                                            │
│             Main Content                   │
│                                            │
├──────────────────────┬─────────────────────┤
│ Article               │ Sidebar             │
│                       │                     │
└──────────────────────┴─────────────────────┘

Mobile:

┌──────────────────┐
│ Logo       ☰     │
├──────────────────┤
│                  │
│ Main Content     │
│                  │
│                  │
├──────────────────┤
│ Sidebar content  │
└──────────────────┘

The content and semantics remain meaningful, while CSS can change the visual arrangement.


2. Responsive HTML vs Responsive CSS#

This distinction is important.

HTML:

<main>
    <article>
        <h1>AI Agents</h1>
        <p>...</p>
    </article>
 
    <aside>
        Related articles
    </aside>
</main>

CSS determines whether these appear:

Desktop:
 
Article | Aside

or:

Mobile:
 
Article
Aside

So:

HTML → Structure + meaning
CSS  → Layout + appearance
JavaScript → Behavior

3. The Viewport#

You learned this in Chapter 14.

For responsive websites, a typical document contains:

<meta
    name="viewport"
    content="width=device-width, initial-scale=1.0">

Without an appropriate viewport configuration, mobile browsers may use a layout viewport that doesn't correspond to the device's CSS pixel width in the way you expect.


4. Why width=device-width Matters#

Consider a phone that has a physical display around:

390 CSS pixels wide

You want your layout to respond to approximately that viewport width.

<meta
    name="viewport"
    content="width=device-width, initial-scale=1.0">

Conceptually:

Device
┌─────────────────┐
│                 │
│   390px         │
│   viewport      │
│                 │
└─────────────────┘
        ↓
HTML/CSS layout

5. Mobile-First Thinking#

A common professional approach is:

Design for smaller screens first, then progressively enhance the layout for larger screens.

For example:

Mobile
   ↓
Tablet
   ↓
Desktop
   ↓
Large Desktop

Instead of:

Desktop
   ↓
Try to squeeze everything into mobile

6. Why Mobile-First?#

Mobile-first encourages you to prioritize:

Essential content
     ↓
Essential navigation
     ↓
Essential actions

rather than trying to fit every desktop element onto a tiny screen.

Example:

Desktop:
┌────────────────────────────────────┐
│ Logo | Home | Blog | Docs | Login │
└────────────────────────────────────┘

Mobile may become:

┌──────────────────┐
│ Logo          ☰  │
└──────────────────┘

with the navigation revealed when needed.


7. HTML Should Not Be Duplicated Unnecessarily#

A beginner might write:

<!-- Desktop navigation -->
<nav class="desktop-nav">
    ...
</nav>
 
<!-- Mobile navigation -->
<nav class="mobile-nav">
    ...
</nav>

This can result in duplicate content and potentially duplicate interactive controls.

Often, a better architecture is:

<nav aria-label="Main navigation">
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/about">About</a></li>
    </ul>
</nav>

Then CSS/JavaScript controls how the same navigation behaves across screen sizes.


8. Responsive Images#

Images are one of the most important responsive HTML topics.

A basic image:

<img
    src="/images/hero.jpg"
    alt="AI agent architecture">

works, but the browser has only one primary image resource to choose from.

Suppose you have:

hero-small.jpg   → 480px
hero-medium.jpg  → 800px
hero-large.jpg   → 1600px

Sending the 1600px image to every mobile user wastes bandwidth.

Responsive images solve this.


9. srcset#

Example:

<img
    src="/images/hero-800.jpg"
    srcset="
        /images/hero-480.jpg 480w,
        /images/hero-800.jpg 800w,
        /images/hero-1600.jpg 1600w
    "
    alt="AI agent architecture">

The browser gets multiple candidate resources.

The values:

480w
800w
1600w

describe the image's intrinsic width in pixels.


10. What Does 480w Mean?#

It does not mean:

Display this image at 480 CSS pixels.

It means:

This resource is approximately 480 pixels wide.

For example:

hero-480.jpg
     ↓
480w
 
hero-800.jpg
     ↓
800w
 
hero-1600.jpg
     ↓
1600w

The browser uses these candidates together with information about the rendered size and device pixel ratio.


11. Why src Is Still Included#

Example:

<img
    src="/images/hero-800.jpg"
    srcset="
        /images/hero-480.jpg 480w,
        /images/hero-800.jpg 800w,
        /images/hero-1600.jpg 1600w"
    alt="AI agent architecture">

src provides a default/fallback resource.

Modern browsers that understand srcset can select an appropriate candidate.


12. sizes#

srcset alone doesn't tell the browser how large the image will actually appear in the layout.

That's where sizes helps.

Example:

<img
    src="/images/hero-800.jpg"
    srcset="
        /images/hero-480.jpg 480w,
        /images/hero-800.jpg 800w,
        /images/hero-1600.jpg 1600w"
    sizes="
        (max-width: 600px) 100vw,
        (max-width: 1000px) 80vw,
        800px"
    alt="AI agent architecture">

Now the browser has more information.


13. Understanding sizes#

This:

sizes="
    (max-width: 600px) 100vw,
    (max-width: 1000px) 80vw,
    800px"

roughly means:

If viewport ≤ 600px
    image display width ≈ 100vw
 
Otherwise if viewport ≤ 1000px
    image display width ≈ 80vw
 
Otherwise
    image display width ≈ 800px

14. What Is vw?#

vw means:

viewport width

So:

100vw

means approximately:

100% of viewport width

and:

50vw

means approximately:

50% of viewport width

Example:

Viewport = 400px
 
100vw ≈ 400px
50vw  ≈ 200px

15. How Browser Chooses an Image#

Conceptually:

HTML
 │
 ├── srcset
 │      ├── 480w
 │      ├── 800w
 │      └── 1600w
 │
 └── sizes
        ↓
What width will image occupy?
        ↓
Device pixel ratio
        ↓
Browser chooses suitable candidate

You don't manually write:

if (mobile) {
    load small image
}

The browser handles resource selection.


16. Responsive Image Example#

<img
    src="/images/product-800.jpg"
    srcset="
        /images/product-400.jpg 400w,
        /images/product-800.jpg 800w,
        /images/product-1200.jpg 1200w"
    sizes="
        (max-width: 600px) 100vw,
        (max-width: 900px) 50vw,
        400px"
    alt="Black wireless headphones"
    width="1200"
    height="1200">

Notice:

srcset → available resources
sizes  → expected display width
alt    → accessibility
width/height → intrinsic dimensions/aspect ratio information

17. Why width and height Still Matter#

You learned that width and height can help prevent layout shifts.

Example:

<img
    src="/images/product.jpg"
    alt="Wireless headphones"
    width="1200"
    height="1200">

The browser knows the intrinsic aspect ratio:

1200 : 1200
     ↓
1 : 1

Before the image loads, it can reserve the appropriate space.

This helps reduce unexpected layout movement.


18. Responsive Image ≠ CSS width: 100%#

You might see:

img {
    width: 100%;
    height: auto;
}

This makes an image responsive in layout.

But it doesn't necessarily solve the bandwidth problem.

For example:

One 3000px image
        ↓
Mobile
        ↓
Browser downloads huge image
        ↓
CSS shrinks it

Better:

Multiple image candidates
        ↓
Browser selects suitable resource
        ↓
Mobile downloads smaller resource

This is the difference between:

responsive display and responsive image delivery.


19. <picture>#

<picture> provides more advanced image selection.

Example:

<picture>
 
    <source
        media="(max-width: 600px)"
        srcset="/images/mobile.jpg">
 
    <source
        media="(min-width: 601px)"
        srcset="/images/desktop.jpg">
 
    <img
        src="/images/desktop.jpg"
        alt="AI technology illustration">
 
</picture>

The browser chooses an appropriate source.


20. Why Use <picture>?#

<picture> is especially useful when you need:

Art direction#

Different crops/compositions for different screen sizes.

For example:

Desktop:

┌──────────────────────────────────────────┐
│                                          │
│      Person + Laptop + Office            │
│                                          │
└──────────────────────────────────────────┘

Mobile:

┌────────────────┐
│                │
│    Person      │
│                │
└────────────────┘

These aren't merely different resolutions.

They're different compositions.


21. srcset vs <picture>#

Requirement Use
Same image, different resolutions srcset
Same image, different display sizes srcset + sizes
Different crops <picture>
Different formats <picture>
Art direction <picture>

22. Modern Image Formats#

You may encounter:

JPEG
PNG
WebP
AVIF
SVG

For photographic content, modern formats such as WebP and AVIF can provide useful compression.

You can use <picture> to provide format alternatives.

Example:

<picture>
 
    <source
        type="image/avif"
        srcset="/images/hero.avif">
 
    <source
        type="image/webp"
        srcset="/images/hero.webp">
 
    <img
        src="/images/hero.jpg"
        alt="AI technology illustration">
 
</picture>

The browser can choose a supported format.


23. Responsive Video#

From Chapter 12:

<video controls>
    <source
        src="/videos/intro.mp4"
        type="video/mp4">
</video>

CSS can make it responsive:

video {
    width: 100%;
    height: auto;
}

Or use a wrapper:

<div class="video-wrapper">
    <video controls>
        <source
            src="/videos/intro.mp4"
            type="video/mp4">
    </video>
</div>
.video-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
}
 
.video-wrapper video {
    width: 100%;
    height: 100%;
}

24. Responsive YouTube Iframe#

You learned this in Chapter 13.

<div class="video-wrapper">
 
    <iframe
        src="https://www.youtube.com/embed/VIDEO_ID"
        title="HTML tutorial"
        loading="lazy"
        allowfullscreen>
    </iframe>
 
</div>

CSS:

.video-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
}
 
.video-wrapper iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

This works across screen sizes.


25. Responsive Tables#

Tables can be problematic on mobile.

Desktop:

┌──────────┬──────────┬──────────┬──────────┐
│ Employee │ Dept     │ Salary   │ Location │
├──────────┼──────────┼──────────┼──────────┤
│ Anubhav  │ Eng      │ ₹26.5L   │ Delhi    │
└──────────┴──────────┴──────────┴──────────┘

Mobile:

┌──────────────────┐
│ Employee | Dept  │
│ Salary   | City  │
└──────────────────┘

A common solution is horizontal scrolling.

<div class="table-wrapper">
 
    <table>
        ...
    </table>
 
</div>
.table-wrapper {
    overflow-x: auto;
}

Now:

Mobile
┌────────────────────┐
│ Employee | Dept... │ → scroll
└────────────────────┘

26. Don't Destroy Table Semantics#

A common mistake is turning every table into:

div
div
div
div

just to make it responsive.

If the data is truly tabular, preserve:

<table>
<thead>
<tbody>
<tr>
<th>
<td>

Then use CSS to make it usable on smaller screens.


27. Responsive Forms#

Forms need special attention on mobile.

Desktop:

First Name     Last Name
[________]     [________]
 
Email
[________________________]
 
Password
[________________________]

Mobile:

First Name
[____________]
 
Last Name
[____________]
 
Email
[____________]
 
Password
[____________]

The same HTML can often support both.

<form>
 
    <div class="form-group">
        <label for="first-name">
            First name
        </label>
 
        <input
            id="first-name"
            name="first_name"
            type="text">
    </div>
 
    <div class="form-group">
        <label for="last-name">
            Last name
        </label>
 
        <input
            id="last-name"
            name="last_name"
            type="text">
    </div>
 
</form>

CSS controls the layout.


28. Don't Use HTML Tables for Form Layout#

Old approach:

<table>
    <tr>
        <td>Name</td>
        <td>
            <input>
        </td>
    </tr>
</table>

Don't do this for layout.

Use semantic form structure:

<label for="name">Name</label>
<input id="name" name="name">

Then CSS handles layout.


29. Touch-Friendly Controls#

Mobile users often interact with fingers rather than a precise mouse pointer.

Don't create tiny controls like:

[×]

with almost no clickable area.

Use sufficient target size and spacing.

Example:

button,
a {
    min-height: 44px;
}

The exact dimensions depend on your design system and platform guidance, but the principle is:

Interactive controls should be easy to accurately activate.


30. Don't Rely on Hover#

Desktop users have:

Mouse
  ↓
Hover

Mobile users may not.

So don't make essential information available only through:

:hover

For example:

Hover over icon → important information appears

may fail on touch devices.

Important information should have an accessible interaction model that doesn't depend solely on hover.


31. Responsive Navigation#

Desktop:

┌──────────────────────────────────────────┐
│ Logo  Home  Blog  Courses  About  Login │
└──────────────────────────────────────────┘

Mobile:

┌────────────────────┐
│ Logo            ☰  │
└────────────────────┘

The HTML can remain semantic:

<header>
 
    <a href="/">
        NextGen Blog
    </a>
 
    <button
        type="button"
        aria-expanded="false"
        aria-controls="main-menu">
        Menu
    </button>
 
    <nav
        id="main-menu"
        aria-label="Main navigation">
 
        <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/blog">Blog</a></li>
            <li><a href="/courses">Courses</a></li>
            <li><a href="/about">About</a></li>
        </ul>
 
    </nav>
 
</header>

CSS and JavaScript can control how the navigation behaves on mobile.


32. Responsive Layout Structure#

Consider a blog:

<main>
 
    <div class="content-layout">
 
        <article>
            <h1>AI Agents</h1>
            ...
        </article>
 
        <aside>
            <h2>Related Articles</h2>
            ...
        </aside>
 
    </div>
 
</main>

Desktop CSS might produce:

┌─────────────────────────────────────┐
│ Article              │ Related      │
│                      │ Articles     │
│                      │              │
└──────────────────────┴──────────────┘

Mobile:

┌──────────────────────┐
│ Article              │
│                      │
├──────────────────────┤
│ Related Articles     │
└──────────────────────┘

The semantic structure remains intact.


33. HTML Should Follow Content Priority#

Suppose you have:

Article
Advertisement
Related articles
Newsletter

On mobile, the user may need:

Article
Related articles
Newsletter
Advertisement

Don't duplicate the entire page just to change visual order.

Use meaningful HTML order and CSS layout intentionally.


34. CSS Grid and Responsive HTML#

HTML:

<main>
 
    <article>
        ...
    </article>
 
    <aside>
        ...
    </aside>
 
</main>

CSS:

main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}
 
@media (min-width: 900px) {
    main {
        grid-template-columns: 2fr 1fr;
    }
}

Mobile:

Article
Aside

Desktop:

Article | Aside

HTML remains semantic.


35. CSS Flexbox#

Example:

.navigation {
    display: flex;
    gap: 1rem;
}

At smaller widths:

@media (max-width: 700px) {
    .navigation {
        flex-direction: column;
    }
}

Again:

HTML
 ↓
Same semantic content
 
CSS
 ↓
Different visual layout

36. Media Queries#

A media query allows CSS to adapt based on conditions.

Example:

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
}

But be careful.

If the sidebar contains important content, simply hiding it on mobile may be a poor design.

A better solution may be to move it below the main content.


37. Hiding vs Reorganizing#

Bad:

@media (max-width: 768px) {
    .important-content {
        display: none;
    }
}

If that content is essential, you've created a mobile accessibility/content problem.

Better:

Desktop:
Main | Important content
 
Mobile:
Main
Important content

Use responsive layout rather than removing meaningful information unnecessarily.


38. Responsive Typography#

HTML:

<h1>
    The Future of AI Agents
</h1>

CSS can adjust the size:

h1 {
    font-size: 2.5rem;
}
 
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }
}

The HTML doesn't change.


39. Avoid Hardcoded Widths#

Bad:

.container {
    width: 1200px;
}

On mobile:

1200px content
      ↓
390px screen
      ↓
Overflow

Better:

.container {
    width: 100%;
    max-width: 1200px;
    margin-inline: auto;
    padding-inline: 1rem;
}

Now:

Mobile
390px
 ↓
container ≈ available width
 
Desktop
1920px
 ↓
container stops at max-width

40. The max-width Pattern#

A very common production pattern:

.container {
    width: min(100% - 2rem, 1200px);
    margin-inline: auto;
}

This gives you:

Small screen
↓
Almost full width
 
Large screen
↓
Maximum readable width

41. Responsive HTML and Accessibility#

Responsive design and accessibility are connected.

Suppose desktop has:

Navigation
Article
Sidebar

On mobile:

Navigation hidden
Article
Sidebar hidden

If the navigation and sidebar contain important functionality, simply hiding them can make the site inaccessible.

Responsive design should preserve:

Content
Functionality
Navigation
Meaning

across screen sizes.


42. Responsive Images + Accessibility#

Don't forget:

<img
    src="/images/hero.jpg"
    srcset="
        /images/hero-small.jpg 480w,
        /images/hero-large.jpg 1200w"
    alt="Developer building an AI application"
    width="1200"
    height="675">

This combines:

srcset → performance
sizes  → resource selection
alt    → accessibility
width/height → layout stability

43. Responsive <picture> + Accessibility#

Example:

<picture>
 
    <source
        media="(max-width: 600px)"
        srcset="/images/mobile-office.jpg">
 
    <source
        media="(min-width: 601px)"
        srcset="/images/desktop-office.jpg">
 
    <img
        src="/images/desktop-office.jpg"
        alt="Developers working together in an office">
 
</picture>

The alt belongs on the fallback <img>.

The <source> elements don't have their own alt.


44. Responsive HTML for High-Density Displays#

A device may have a device pixel ratio greater than 1.

For example:

CSS width: 390px
Physical pixels: much more

The browser can select higher-resolution image candidates when appropriate.

That's one reason srcset is useful.

Example:

<img
    src="/images/logo.png"
    srcset="
        /images/logo.png 1x,
        /images/logo@2x.png 2x"
    alt="NextGen Blog">

Here:

1x → normal resolution
2x → higher-density candidate

45. srcset Width vs Density Descriptors#

There are two common styles.

Width descriptors#

srcset="
    image-480.jpg 480w,
    image-800.jpg 800w,
    image-1200.jpg 1200w"

Usually paired with:

sizes="..."

Pixel-density descriptors#

srcset="
    logo.png 1x,
    logo@2x.png 2x"

These are useful for fixed-size images such as icons/logos.


46. Responsive Backgrounds vs HTML Images#

If an image conveys meaningful information:

Prefer:

<img
    src="/images/product.jpg"
    alt="Black wireless headphones">

rather than hiding it in CSS:

.product {
    background-image: url("/images/product.jpg");
}

CSS background images are generally better suited to decorative visuals.

This is another accessibility principle:

Meaningful content belongs in HTML whenever appropriate.


47. Responsive Decorative Images#

If something is purely decorative:

.hero {
    background-image: url("/images/pattern.svg");
}

can be appropriate.

The browser doesn't need an alt because the image isn't content.


48. Responsive Embedded Content#

From Chapter 13:

<div class="embed">
    <iframe
        src="..."
        title="Embedded content"
        loading="lazy">
    </iframe>
</div>

CSS:

.embed {
    width: 100%;
    aspect-ratio: 16 / 9;
}
 
.embed iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

This pattern can be used for:

YouTube
Maps
External dashboards
Other embedded applications

49. Orientation#

Devices can rotate.

Portrait
┌───────┐
│       │
│       │
│       │
└───────┘
 
Landscape
┌─────────────────┐
│                 │
└─────────────────┘

Your layout should not assume only portrait or landscape.

CSS can respond to orientation when appropriate:

@media (orientation: landscape) {
    ...
}

But don't design separate websites unnecessarily.


50. Responsive Content Strategy#

Ask these questions:

What is essential?#

Main article
Primary CTA
Navigation

What can move?#

Sidebar
Related content
Secondary information

What can be deferred?#

Heavy embeds
Large images
Secondary widgets

What should never disappear?#

Critical information
Essential controls
Primary navigation

This is responsive design at the architectural level.


51. A Production Responsive Page#

<!DOCTYPE html>
 
<html lang="en">
 
<head>
 
    <meta charset="UTF-8">
 
    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0">
 
    <title>
        AI Agents — NextGen Blog
    </title>
 
    <meta
        name="description"
        content="Learn how AI agents are changing modern software development.">
 
</head>
 
<body>
 
    <a href="#main-content">
        Skip to main content
    </a>
 
    <header>
 
        <div class="container">
 
            <a href="/">
                NextGen Blog
            </a>
 
            <button
                type="button"
                aria-expanded="false"
                aria-controls="main-navigation">
                Menu
            </button>
 
            <nav
                id="main-navigation"
                aria-label="Main navigation">
 
                <ul>
                    <li>
                        <a href="/">Home</a>
                    </li>
 
                    <li>
                        <a href="/ai">AI</a>
                    </li>
 
                    <li>
                        <a href="/development">
                            Development
                        </a>
                    </li>
 
                    <li>
                        <a href="/about">About</a>
                    </li>
                </ul>
 
            </nav>
 
        </div>
 
    </header>
 
    <main id="main-content">
 
        <div class="container">
 
            <article>
 
                <header>
                    <h1>
                        AI Agents Are Changing Software Development
                    </h1>
 
                    <p>
                        Published October 1, 2026
                    </p>
                </header>
 
                <figure>
 
                    <img
                        src="/images/ai-agents-800.jpg"
                        srcset="
                            /images/ai-agents-480.jpg 480w,
                            /images/ai-agents-800.jpg 800w,
                            /images/ai-agents-1200.jpg 1200w"
                        sizes="
                            (max-width: 600px) 100vw,
                            (max-width: 1000px) 90vw,
                            800px"
                        alt="AI agent workflow connecting multiple software tools"
                        width="1200"
                        height="675">
 
                    <figcaption>
                        AI agents can coordinate multiple tools
                        to complete tasks.
                    </figcaption>
 
                </figure>
 
                <p>
                    AI agents are changing how modern software
                    applications are designed.
                </p>
 
                <h2>
                    What Are AI Agents?
                </h2>
 
                <p>
                    An AI agent can reason about a task,
                    use tools, and take actions.
                </p>
 
            </article>
 
            <aside>
                <h2>Related Articles</h2>
 
                <ul>
                    <li>
                        <a href="/rag">
                            Understanding RAG
                        </a>
                    </li>
 
                    <li>
                        <a href="/vector-databases">
                            Vector Databases Explained
                        </a>
                    </li>
                </ul>
            </aside>
 
        </div>
 
    </main>
 
    <footer>
 
        <div class="container">
 
            <p>
                © 2026 NextGen Blog
            </p>
 
        </div>
 
    </footer>
 
</body>
 
</html>

Notice something important:

The HTML itself doesn't contain desktop/mobile-specific content.

It contains meaningful structure.

CSS can then transform that structure into different layouts.


52. Common Responsive Mistakes#

Mistake 1 — Fixed width#

.container {
    width: 1200px;
}

Can cause mobile overflow.


Mistake 2 — Huge images everywhere#

<img src="4000px-image.jpg">

and then:

img {
    width: 300px;
}

The browser may still download the huge source.

Use responsive image techniques.


Mistake 3 — Duplicate mobile and desktop HTML#

<div class="desktop">
    ...
</div>
 
<div class="mobile">
    ...
</div>

This can create:

  • duplicate content
  • duplicate controls
  • accessibility problems
  • maintenance complexity

Prefer a shared semantic structure where practical.


Mistake 4 — Hiding important content#

@media (max-width: 600px) {
    .important {
        display: none;
    }
}

Don't remove essential content just because the screen is small.


Mistake 5 — Tiny touch targets#

[ x ]

with almost no clickable area.

Make interactive elements comfortable to use.


Mistake 6 — Hover-only interaction#

Don't make essential functionality available only on hover.


Mistake 7 — Desktop-first thinking everywhere#

Trying to shrink a complex desktop layout into a phone often produces poor UX.

Start with the content and interactions that matter most.


53. Responsive HTML Cheat Sheet#

Responsive HTML
│
├── Viewport
│   └── <meta name="viewport">
│
├── Images
│   ├── srcset
│   ├── sizes
│   └── <picture>
│
├── Formats
│   ├── WebP
│   ├── AVIF
│   └── fallback
│
├── Video
│   └── responsive <video>
│
├── Iframes
│   └── responsive embeds
│
├── Tables
│   └── horizontal scrolling
│
├── Forms
│   └── flexible layouts
│
├── Navigation
│   └── responsive interaction
│
├── Accessibility
│   ├── keyboard
│   ├── focus
│   └── semantic HTML
│
└── Layout
    ├── Flexbox
    ├── Grid
    └── Media queries

54. Responsive Design Mental Model#

Remember this:

                 USER
                  │
                  ↓
          Available viewport
                  │
                  ↓
              HTML
                  │
       ┌──────────┴──────────┐
       ↓                     ↓
   Structure              Content
       │                     │
       └──────────┬──────────┘
                  ↓
                 CSS
                  │
        ┌─────────┴─────────┐
        ↓                   ↓
     Mobile              Desktop
        │                   │
        ↓                   ↓
     Layout              Layout

The HTML shouldn't be designed as:

"desktop HTML"
"mobile HTML"

Instead:

Build meaningful HTML, then allow CSS and responsive browser features to adapt its presentation.


55. Interview Questions#

Q1. What is responsive web design?#

A design approach where a website adapts its layout and resources to different viewport sizes and device characteristics.

Q2. Why do we use the viewport meta tag?#

To configure the layout viewport appropriately for modern responsive pages.

Q3. What is srcset?#

It provides multiple image resource candidates so the browser can select an appropriate one.

Q4. What is sizes?#

It tells the browser the expected rendered width of an image under different viewport conditions, helping it choose from srcset.

Q5. What is <picture>?#

A container for multiple image sources, useful for art direction and format selection.

Q6. Difference between srcset and <picture>?#

srcset is commonly used to select among different resolutions/sizes of the same image, while <picture> allows different sources based on media conditions or formats.

Q7. Why should images have width and height?#

They provide intrinsic dimensions/aspect-ratio information and can help the browser reserve space before an image loads.

Q8. How do you make an iframe responsive?#

A common approach is:

.wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
}
 
.wrapper iframe {
    width: 100%;
    height: 100%;
}

Q9. Should you create separate HTML for mobile and desktop?#

Usually no. Prefer a shared semantic structure and responsive CSS/behavior.

Q10. Why is mobile-first useful?#

It encourages prioritizing essential content and progressively enhancing the layout for larger screens.


56. Mini Project — Responsive NextGen Blog#

Create:

responsive-blog.html

Build:

┌──────────────────────────────────────────┐
│              Desktop                     │
├──────────────────────────────────────────┤
│ Logo     Home Blog AI Courses About      │
├──────────────────────────────────────────┤
│                                          │
│ Article                       Sidebar    │
│                                          │
│ [Responsive Hero Image]                  │
│                                          │
│ Article content                          │
│                                          │
└──────────────────────────────────────────┘

On mobile:

┌────────────────────┐
│ Logo            ☰  │
├────────────────────┤
│                    │
│ Article             │
│                    │
│ [Hero Image]       │
│                    │
│ Content            │
│                    │
├────────────────────┤
│ Related Articles   │
└────────────────────┘

Requirements:

✓ Responsive viewport
✓ Semantic HTML
✓ Responsive navigation
✓ Responsive image
✓ srcset
✓ sizes
✓ <picture>
✓ Responsive video
✓ Responsive iframe
✓ Responsive table
✓ Responsive form
✓ Keyboard accessible
✓ Visible focus
✓ Mobile-friendly controls
✓ No horizontal page overflow

Next Chapter#

Chapter 17 — Modern HTML APIs#

Next we'll move beyond basic markup and learn the modern browser capabilities that HTML exposes, including:

  • data-* attributes
  • contenteditable
  • draggable
  • spellcheck
  • hidden
  • inert
  • <dialog>
  • Popovers
  • <details> and <summary>
  • <template>
  • <slot>
  • popover
  • Native dialogs
  • Form-associated browser features
  • autocomplete
  • inputmode
  • enterkeyhint
  • capture
  • Drag-and-drop basics
  • Browser interaction APIs
  • HTML + JavaScript integration
  • Accessibility implications
  • Security considerations
  • Real-world examples
  • Interview questions
  • A practical modern HTML API project

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 15 — Accessibility (A11y)Course CompletedReturn to Syllabus
Prev