Internet Programming Laboratory

Unit 2: Advanced HTML5 & Responsive Design

Lists, Links, Images, Media, Tables, and HTML5 Forms โ€” build real web pages that work on every device.

๐Ÿข Industry-Aligned  |  ๐Ÿ“ 15 MCQs (Bloom's Taxonomy)  |  ๐Ÿ”ฌ 5 Lab Exercises  |  ๐Ÿ’ผ Interview Prep

Section 1

Why This Chapter Matters in 2025

Unit 1 gave you the skeleton. Unit 2 gives you the muscles and organs. Every real website needs: navigation lists, clickable links, optimized images, embedded videos, data tables, and user input forms. This unit covers every one of these โ€” using modern HTML5 standards that Indian IT companies expect in 2025.

๐Ÿข Industry Connection โ€” Who Uses These Features?

IRCTC โ€” India's largest booking platform relies on HTML5 forms with 15+ input types (date pickers, dropdowns, radio buttons) to book 15 lakh tickets daily. A single validation error = thousands of failed bookings.

Swiggy โ€” Every restaurant menu is a nested list (<ul> inside <ul>). Every dish image uses srcset for responsive loading โ€” serving smaller images on mobile to save bandwidth.

OYO โ€” Hotel listings display room details in accessible tables with scope and caption. Their booking form uses HTML5 validation attributes (required, pattern, min, max) for client-side validation before the data even hits the server.

๐Ÿ‡ฎ๐Ÿ‡ณ IRCTC๐Ÿ‡ฎ๐Ÿ‡ณ Swiggy๐Ÿ‡ฎ๐Ÿ‡ณ OYO๐Ÿ‡ฎ๐Ÿ‡ณ Zepto

Prerequisite Checklist โœ…

  • โœ… Unit 1 completed โ€” HTML5 document structure & semantic elements
  • โœ… Comfortable with <header>, <main>, <article>, <section>
  • โœ… Can create a valid HTML5 page from scratch
Section 2

Learning Outcomes โ€” Bloom's Taxonomy

Bloom's LevelLearning Outcome
L1 โ€” RememberRecall the syntax and purpose of all HTML5 form input types (text, email, date, range, color, tel, number, search)
L2 โ€” UnderstandExplain how srcset and loading="lazy" optimize image performance on mobile networks
L3 โ€” ApplyBuild a complete, accessible HTML5 form with client-side validation using required, pattern, min/max
L4 โ€” AnalyzeAnalyze a data table and determine the correct use of scope, caption, colspan, and rowspan for accessibility
L5 โ€” EvaluateEvaluate whether a given form design meets UX, accessibility, and validation best practices for an Indian fintech app
L6 โ€” CreateDesign and build a complete multi-step booking form (IRCTC-style) with all HTML5 input types and native validation
Section 3

Concept Explanations

3.1 Lists โ€” OL, UL, and DL

Real-World Analogy

Think of lists like a restaurant menu. An unordered list is the menu categories (no ranking). An ordered list is cooking steps (sequence matters). A definition list is the menu legend explaining symbols (๐ŸŒถ๏ธ = Spicy, ๐Ÿฅฌ = Vegan).

HTML5
<!-- ๐Ÿ“ FILE: swiggy-menu.html -->
<!-- ๐Ÿข INDUSTRY CONTEXT: Swiggy/Zomato menu structure -->

<!-- Unordered List โ€” menu categories (no sequence) -->
<h2>๐Ÿ• Menu Categories</h2>
<ul>
  <li>Starters
    <ul>  <!-- Nested list โ€” subcategories -->
      <li>Paneer Tikka โ€” โ‚น249</li>
      <li>Chicken Wings โ€” โ‚น299</li>
    </ul>
  </li>
  <li>Main Course</li>
  <li>Desserts</li>
</ul>

<!-- Ordered List โ€” cooking steps (sequence matters) -->
<h2>๐Ÿง‘โ€๐Ÿณ How to Order on Swiggy</h2>
<ol>
  <li>Open the Swiggy app</li>
  <li>Search for your favourite restaurant</li>
  <li>Add items to cart</li>
  <li>Apply coupon code</li>
  <li>Pay via UPI and wait for delivery ๐Ÿ›ต</li>
</ol>

<!-- Definition List โ€” key-value pairs -->
<h2>๐Ÿท๏ธ Menu Legend</h2>
<dl>
  <dt>๐ŸŸข</dt>  <dd>Vegetarian</dd>
  <dt>๐Ÿ”ด</dt>  <dd>Non-Vegetarian</dd>
  <dt>๐ŸŒถ๏ธ</dt>  <dd>Spicy โ€” may contain chillies</dd>
  <dt>โญ</dt>  <dd>Chef's Special</dd>
</dl>
HTML5
<!-- Basic link -->
<a href="https://www.irctc.co.in">Book Train Tickets</a>

<!-- Open in new tab (external links should ALWAYS do this) -->
<a href="https://www.irctc.co.in" target="_blank" rel="noopener noreferrer">
  IRCTC Official Site โ†—
</a>

<!-- INDUSTRY NOTE: rel="noopener noreferrer" prevents:
     1. The new tab from accessing window.opener (security)
     2. Referrer header leaking (privacy)
     Every Indian company's security audit requires this. -->

<!-- Internal page link (anchor) -->
<a href="#contact">Jump to Contact Section</a>

<!-- Email link -->
<a href="mailto:support@shopdesi.in">Email Us</a>

<!-- Phone link (crucial for mobile UX) -->
<a href="tel:+911800123456">๐Ÿ“ž Call: 1800-123-456</a>

<!-- Download link -->
<a href="brochure.pdf" download>๐Ÿ“ฅ Download Brochure</a>

Students write target="_blank" without rel="noopener noreferrer". This is a security vulnerability โ€” the new tab can access window.opener and redirect your original page to a phishing site. This is flagged in every security audit at TCS, Infosys, and Wipro.

3.3 Images โ€” Optimization with srcset & Lazy Loading

โŒ Before โ€” One size for all devices
<img src="product-1920.jpg"
     alt="Cotton Kurti">
<!-- Mobile downloads a 2MB desktop image
     on a 4G connection. Wastes bandwidth. -->
โœ… After โ€” Responsive with srcset & lazy loading
<img
  src="product-800.jpg"
  srcset="product-400.jpg 400w,
         product-800.jpg 800w,
         product-1200.jpg 1200w"
  sizes="(max-width:600px) 400px,
        (max-width:1024px) 800px,
        1200px"
  alt="Cotton Kurti Set - Red"
  loading="lazy"
  width="800" height="600">
<!-- Browser picks the best image for device.
     loading="lazy" defers off-screen images. -->

Lazy Loading โ€” Images below the fold (not visible on screen) are NOT downloaded until the user scrolls near them. loading="lazy" is a native HTML5 attribute โ€” no JavaScript needed. Flipkart's product listing page has 50+ images; lazy loading saves ~60% bandwidth on initial page load.

The alt attribute is not optional. It must describe the image content: alt="Red Cotton Kurti Set with gold embroidery", not alt="image" or alt="photo". For decorative images (icons, backgrounds), use alt="" (empty) to tell screen readers to skip them. Always include width and height to prevent layout shift (CLS).

3.4 Embedding Media โ€” Audio, Video & Iframe

HTML5
<!-- ๐Ÿ“ FILE: media-embed.html -->
<!-- ๐Ÿข INDUSTRY CONTEXT: YouTube-style video player, Spotify-style audio -->

<!-- HTML5 Video โ€” native player, no Flash needed -->
<video controls width="640" height="360" poster="thumbnail.jpg" preload="metadata">
  <source src="intro.mp4" type="video/mp4">
  <source src="intro.webm" type="video/webm">
  <p>Your browser doesn't support HTML5 video.
     <a href="intro.mp4">Download the video</a>.</p>
</video>

<!-- HTML5 Audio -->
<audio controls preload="none">
  <source src="podcast.mp3" type="audio/mpeg">
  <source src="podcast.ogg" type="audio/ogg">
  Your browser doesn't support HTML5 audio.
</audio>

<!-- Iframe โ€” embed YouTube, Google Maps, etc. -->
<iframe
  src="https://www.youtube.com/embed/dQw4w9WgXcQ"
  width="560" height="315"
  title="Product Demo Video"
  allow="accelerometer; autoplay; encrypted-media"
  allowfullscreen
  loading="lazy">
</iframe>

3.5 Tables with Accessibility

When to use tables

Tables are for tabular data only โ€” timetables, price comparisons, reports. Never use tables for page layout (that's a 1990s practice โ€” use CSS Grid/Flexbox instead).

HTML5
<!-- ๐Ÿ“ FILE: oyo-room-listing.html -->
<!-- ๐Ÿข INDUSTRY CONTEXT: OYO room comparison table -->

<table>
  <caption>OYO Townhouse โ€” Room Types & Pricing (Bangalore)</caption>

  <thead>
    <tr>
      <th scope="col">Room Type</th>
      <th scope="col">Price/Night</th>
      <th scope="col">Capacity</th>
      <th scope="col">WiFi</th>
      <th scope="col">Breakfast</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <th scope="row">Standard</th>
      <td>โ‚น1,299</td>
      <td>2 guests</td>
      <td>โœ…</td>
      <td>โŒ</td>
    </tr>
    <tr>
      <th scope="row">Deluxe</th>
      <td>โ‚น2,499</td>
      <td>2 guests</td>
      <td>โœ…</td>
      <td>โœ…</td>
    </tr>
    <tr>
      <th scope="row">Suite</th>
      <td colspan="2">โ‚น4,999 (fits 4 guests)</td>
      <td>โœ…</td>
      <td>โœ… + Dinner</td>
    </tr>
  </tbody>

  <tfoot>
    <tr>
      <td colspan="5"><small>All prices inclusive of GST. Check-in: 12 PM, Check-out: 11 AM</small></td>
    </tr>
  </tfoot>
</table>

scope="col" tells screen readers "this header applies to the entire column." scope="row" tells it "this header applies to the entire row." Without scope, a blind user hearing "โ‚น2,499" doesn't know which room type it belongs to. <caption> is the table's title โ€” visible and announced by screen readers. These are WCAG 2.1 requirements.

3.6 HTML5 Forms โ€” The Most Important Section

Why forms matter

Forms are how users talk to your application. Every login, registration, booking, payment, and search is a form. IRCTC processes 15 lakh bookings/day โ€” each one starts with a form. Get forms wrong, and users abandon your app.

Form Attributes
AttributePurposeExample
actionURL where form data is sentaction="/api/register"
methodHTTP method (GET for search, POST for sensitive data)method="POST"
enctypeEncoding for file uploadsenctype="multipart/form-data"
novalidateSkip browser validation (for custom JS validation)novalidate
Complete HTML5 Form with All Input Types
HTML5
<!-- ๐Ÿ“ FILE: irctc-booking-form.html -->
<!-- ๐Ÿข INDUSTRY CONTEXT: IRCTC-style train booking form -->
<!-- โš ๏ธ COMMON ERROR: Forgetting 'name' attribute = data not sent to server -->

<form action="/api/book-ticket" method="POST" enctype="multipart/form-data">

  <!-- Fieldset groups related inputs with a visible legend -->
  <fieldset>
    <legend>๐Ÿš† Passenger Details</legend>

    <!-- Text input with validation -->
    <label for="fullName">Full Name (as on ID):</label>
    <input type="text" id="fullName" name="fullName"
           required minlength="3" maxlength="50"
           placeholder="e.g., Rahul Sharma"
           autocomplete="name">

    <!-- Email with built-in validation -->
    <label for="email">Email:</label>
    <input type="email" id="email" name="email"
           required placeholder="rahul@gmail.com">

    <!-- Tel โ€” mobile keyboard shows number pad -->
    <label for="phone">Mobile Number:</label>
    <input type="tel" id="phone" name="phone"
           required pattern="[6-9]\d{9}"
           title="Indian mobile: 10 digits starting with 6-9"
           placeholder="9876543210">

    <!-- Number โ€” age with min/max -->
    <label for="age">Age:</label>
    <input type="number" id="age" name="age"
           required min="1" max="120" value="25">

    <!-- Radio buttons โ€” gender -->
    <p>Gender:</p>
    <label><input type="radio" name="gender" value="male" required> Male</label>
    <label><input type="radio" name="gender" value="female"> Female</label>
    <label><input type="radio" name="gender" value="other"> Other</label>
  </fieldset>

  <fieldset>
    <legend>๐Ÿ—“๏ธ Journey Details</legend>

    <!-- Date picker -->
    <label for="travelDate">Travel Date:</label>
    <input type="date" id="travelDate" name="travelDate"
           required min="2025-01-01">

    <!-- Select dropdown -->
    <label for="fromStation">From Station:</label>
    <select id="fromStation" name="fromStation" required>
      <option value="">-- Select Station --</option>
      <option value="NDLS">New Delhi (NDLS)</option>
      <option value="BCT">Mumbai Central (BCT)</option>
      <option value="MAS">Chennai Central (MAS)</option>
      <option value="HWH">Howrah Junction (HWH)</option>
      <option value="SBC">Bangalore City (SBC)</option>
    </select>

    <!-- Datalist โ€” autocomplete search -->
    <label for="toStation">To Station:</label>
    <input type="search" id="toStation" name="toStation"
           list="stations" required placeholder="Type station name...">
    <datalist id="stations">
      <option value="New Delhi (NDLS)">
      <option value="Mumbai Central (BCT)">
      <option value="Jaipur Junction (JP)">
      <option value="Varanasi Junction (BSB)">
    </datalist>

    <!-- Select class (multi-select not needed here but shown) -->
    <label for="travelClass">Class:</label>
    <select id="travelClass" name="travelClass" required>
      <option value="SL">Sleeper (SL)</option>
      <option value="3A">AC 3-Tier (3A)</option>
      <option value="2A">AC 2-Tier (2A)</option>
      <option value="1A" selected>AC First Class (1A)</option>
    </select>

    <!-- Range โ€” number of passengers -->
    <label for="passengers">Passengers: <output id="passOutput">1</output></label>
    <input type="range" id="passengers" name="passengers"
           min="1" max="6" value="1"
           oninput="passOutput.textContent=this.value">
  </fieldset>

  <fieldset>
    <legend>๐ŸŽซ Preferences</legend>

    <!-- Checkboxes โ€” multiple selections -->
    <label><input type="checkbox" name="meal" value="veg"> ๐Ÿฅฌ Veg Meal</label>
    <label><input type="checkbox" name="meal" value="nonveg"> ๐Ÿ— Non-Veg Meal</label>
    <label><input type="checkbox" name="insurance" checked> ๐Ÿ›ก๏ธ Travel Insurance (โ‚น35)</label>

    <!-- Textarea โ€” special requests -->
    <label for="specialReq">Special Requests:</label>
    <textarea id="specialReq" name="specialReq"
              rows="3" cols="50"
              maxlength="200"
              placeholder="e.g., Lower berth preferred, wheelchair assistance"></textarea>

    <!-- Color picker (for fun โ€” theme selection) -->
    <label for="themeColor">Ticket Theme Color:</label>
    <input type="color" id="themeColor" name="themeColor" value="#0369a1">

    <!-- File upload โ€” ID proof -->
    <label for="idProof">Upload ID Proof (Aadhaar/PAN):</label>
    <input type="file" id="idProof" name="idProof"
           accept=".jpg,.png,.pdf">
  </fieldset>

  <!-- Submit & Reset -->
  <button type="submit">๐ŸŽซ Book Ticket</button>
  <button type="reset">๐Ÿ”„ Reset Form</button>

</form>
HTML5 Validation Attributes Reference
AttributeWhat It DoesExample
requiredField must be filledPrevents empty submission
patternRegex validationpattern="[6-9]\d{9}" (Indian mobile)
min / maxRange for number/datemin="1" max="120"
minlength / maxlengthText length limitsminlength="3" maxlength="50"
placeholderHint text (disappears on focus)placeholder="e.g., Rahul"
autocompleteBrowser autofill hintsautocomplete="email"
acceptRestrict file typesaccept=".jpg,.pdf"

HTML5 form validation happens before JavaScript even runs. When you add required and type="email", the browser validates the input natively โ€” no JS needed. This is faster, more accessible (screen readers announce validation errors), and works even if JS is disabled. JavaScript validation should be a second layer, not the only layer.

Section 4

Real-Life Industry Problems

๐Ÿข INDUSTRY PROBLEM #1 โ€” Swiggy Restaurant Menu Page

Scenario

Build a restaurant menu page for "Biryani House" on a Swiggy-like platform. The menu must be navigable by screen readers and optimized for 4G mobile connections.

Requirements
  • Nested unordered lists: categories โ†’ dishes (Starters โ†’ Paneer Tikka, Chicken 65)
  • Each dish shows: name, price (<strong>), dietary mark (๐ŸŸข/๐Ÿ”ด), rating
  • Images with srcset (400w, 800w) and loading="lazy"
  • Navigation links to jump to each category (#starters, #mains, #desserts)
  • Definition list for the menu legend (symbols explained)

Interview Angle: "Swiggy asks freshers: How would you structure a menu page for SEO and accessibility?"

๐Ÿข INDUSTRY PROBLEM #2 โ€” OYO Room Comparison Table

Scenario

Build a responsive room comparison table for an OYO-style hotel booking site. The table must be accessible โ€” a blind user should understand which amenities belong to which room type.

Requirements
  • Table with <caption>, <thead>, <tbody>, <tfoot>
  • Use scope="col" and scope="row" for accessibility
  • At least one colspan and one rowspan
  • Footer row with pricing disclaimer
  • 5+ room types with 5+ amenity columns

What This Teaches: Accessible table design. Interview Angle: "WCAG 2.1 compliance is tested in TCS and Wipro audits."

๐Ÿข INDUSTRY PROBLEM #3 โ€” IRCTC Train Booking Form

Scenario

Build a complete train booking form for an IRCTC-style platform. The form must validate all inputs using only HTML5 attributes (no JavaScript). Every field must have proper labels, placeholders, and native validation.

Requirements
  • 3 fieldsets: Passenger Details, Journey Details, Payment
  • Input types: text, email, tel (with Indian mobile pattern), number, date, radio, checkbox, select, datalist, range, file, color, textarea
  • All fields with required, pattern, min/max, placeholder
  • Datalist for station autocomplete
  • File upload for Aadhaar/PAN with accept filter

What This Teaches: Complete HTML5 form design with native validation โ€” the foundation for Unit 5's JS validation.

Section 5

Lab Exercises

๐ŸŸข Beginner Exercise 1: Nested Menu List

Estimated Time: 20 minutes

Create a restaurant menu using nested lists. Main categories (Starters, Main Course, Desserts, Beverages) as <ul>. Each category contains 3+ dishes as nested <li>. Add prices using <strong> and dietary marks (๐ŸŸข/๐Ÿ”ด). Add a definition list (<dl>) explaining the symbols.

Hints: (1) Nest <ul> inside <li>, not inside another <ul> directly. (2) Use <s> for original prices on discounted items.

๐ŸŸข Beginner Exercise 2: Image Gallery with Lazy Loading

Estimated Time: 25 minutes

Create a "Tourist Destinations of India" gallery with 6+ images. Each image must use alt (descriptive), width/height, and loading="lazy". For at least 2 images, add srcset with 2 sizes. Use the <figure> and <figcaption> elements for image captions.

Extension: Embed a YouTube video of "Top 10 Indian Destinations" using <iframe> with loading="lazy" and a title attribute.

๐ŸŸก Intermediate Exercise 3: Accessible Data Table

Estimated Time: 30 minutes

Create an "Indian Railways Fare Chart" table comparing fares across 5 trains (rows) and 4 classes (columns: SL, 3A, 2A, 1A). Include: <caption>, scope attributes, colspan for merged header, and <tfoot> with disclaimer. Make the table pass WAVE accessibility checker.

Hints: (1) Headers need scope="col". (2) Row headers need scope="row". (3) Use <thead>, <tbody>, <tfoot> to group.

๐Ÿ”ด Advanced Exercise 4: Complete Registration Form

Estimated Time: 40 minutes

Build a "Campus Placement Portal" registration form with 3 fieldsets: Personal Details (name, email, phone with Indian pattern, DOB, gender radios), Academic Details (college select, branch datalist, CGPA number 0-10, resume file upload), Preferences (preferred locations checkboxes, expected CTC range slider, cover letter textarea). All fields must have HTML5 validation attributes. Test by clicking Submit without filling โ€” every required field should show a native error.

โšซ Industry-Level Exercise 5: Complete E-Commerce Product Page

Estimated Time: 50 minutes

Build a complete Flipkart-style product detail page with: (1) Image gallery using <figure>, srcset, and lazy loading. (2) Product details in a definition list (Brand, Color, Material, Warranty). (3) Size selection via radio buttons. (4) Quantity selector via number input (min=1, max=10). (5) Specifications in an accessible table. (6) Review form with star rating (range 1-5), comment textarea, and file upload for photos. All content must use semantic HTML. Validate at W3C โ€” zero errors.

Section 6

MCQ Assessment Bank โ€” 15 Questions

Level 1 โ€” Remember โญ

Q1

Which HTML5 input type shows a date picker on mobile browsers?

  1. <input type="text">
  2. <input type="date">
  3. <input type="calendar">
  4. <input type="datetime">
โœ… B
๐Ÿ“– type="date" triggers the native date picker on mobile/desktop. (A) Shows text field. (C) Doesn't exist. (D) datetime is deprecated; use datetime-local.
๐Ÿข Tested in: TCS NQT, AMCAT
L1 Remember
Q2

The <datalist> element provides:

  1. A dropdown select menu
  2. An autocomplete suggestion list for an input field
  3. A data table
  4. A list of downloadable files
โœ… B
๐Ÿ“– <datalist> provides autocomplete suggestions for <input>. Unlike <select>, users can type freely AND pick from suggestions. (A) That's <select>. (C)(D) Unrelated.
๐Ÿข Tested in: Infosys InfyTQ
L1 Remember
Q3

Which attribute is used to group related form controls with a visible title?

  1. <div> + <h3>
  2. <fieldset> + <legend>
  3. <section> + <label>
  4. <group> + <title>
โœ… B
๐Ÿ“– <fieldset> groups related inputs; <legend> provides the group's visible title. Screen readers announce the legend when entering the group. (A) No semantic grouping. (C)(D) Don't exist for this purpose.
๐Ÿข Tested in: Wipro NLTH
L1 Remember

Level 2 โ€” Understand โญโญ

Q4

Why should external links use rel="noopener noreferrer" with target="_blank"?

  1. To improve page loading speed
  2. To prevent the new tab from accessing window.opener (security) and leaking referrer data (privacy)
  3. To enable the link in incognito mode
  4. To make the link SEO-friendly
โœ… B
๐Ÿ“– Without noopener, the new tab can call window.opener.location = 'phishing-site.com' โ€” redirecting your original tab. noreferrer prevents the destination from seeing where the user came from. (A)(C)(D) Incorrect.
๐Ÿข Security audit requirement at all companies
L2 Understand
Q5

What is the purpose of loading="lazy" on images?

  1. It makes images load slower
  2. It defers loading off-screen images until the user scrolls near them, saving bandwidth
  3. It compresses the image file
  4. It adds a fade-in animation
โœ… B
๐Ÿ“– Lazy loading delays downloading images that aren't visible. On a Flipkart page with 50+ product images, only the first ~6 load initially โ€” the rest load as you scroll. Saves 60%+ bandwidth on mobile.
๐Ÿข Google Core Web Vitals metric
L2 Understand
Q6

Why does <input type="tel"> show a numeric keypad on mobile but NOT validate phone format?

  1. It's a browser bug
  2. type="tel" only controls the keyboard layout; phone formats vary by country, so validation requires pattern
  3. It validates on desktop, not mobile
  4. You need JavaScript for the keypad
โœ… B
๐Ÿ“– Indian phones: 10 digits starting 6-9. US: (xxx) xxx-xxxx. UK: +44 xxxx xxxxxx. No single validation works globally. type="tel" just shows the dial pad. Use pattern="[6-9]\d{9}" for Indian numbers.
๐Ÿข UX design principle
L2 Understand

Level 3 โ€” Apply โญโญ

Q7

Which code correctly validates an Indian mobile number (10 digits, starts with 6-9)?

  1. <input type="number" min="6000000000" max="9999999999">
  2. <input type="tel" pattern="[6-9]\d{9}" required>
  3. <input type="phone" validate="indian">
  4. <input type="text" maxlength="10">
โœ… B
๐Ÿ“– type="tel" shows numeric keypad. pattern enforces regex. [6-9] = first digit 6-9. \d{9} = exactly 9 more digits. (A) Number type strips leading zeros. (C) No "phone" type. (D) No format validation.
๐Ÿข Every Indian fintech form uses this pattern
L3 Apply
Q8

Which code correctly creates a table header that a screen reader can associate with its column data?

  1. <td class="header">Price</td>
  2. <th>Price</th>
  3. <th scope="col">Price</th>
  4. <strong>Price</strong>
โœ… C
๐Ÿ“– <th scope="col"> tells assistive technology "this header applies to the entire column below." (B) <th> without scope works but is less explicit. (A)(D) Not table headers at all.
๐Ÿข WCAG 2.1 AA requirement
L3 Apply
Q9

To allow a user to upload only PDF and image files, which attribute is correct?

  1. type="file" filter=".pdf,.jpg"
  2. type="file" accept=".pdf,.jpg,.png"
  3. type="upload" format="pdf,jpg"
  4. type="file" allowed="application/pdf"
โœ… B
๐Ÿ“– accept restricts the file picker dialog to show only matching file types. Note: this is a UI hint, not security โ€” always validate on the server too. (A)(C)(D) Use non-existent attributes.
๐Ÿข IRCTC ID proof upload uses this
L3 Apply

Level 4 โ€” Analyze โญโญโญ

Q10

A form uses method="GET" for a login page. What is the security risk?

  1. No risk โ€” GET and POST are identical for security
  2. GET appends data to the URL โ€” passwords appear in browser history, server logs, and can be bookmarked
  3. GET encrypts data automatically
  4. GET prevents CSRF attacks
โœ… B
๐Ÿ“– GET: /login?username=rahul&password=secret123 โ€” visible in URL bar, browser history, and server access logs. POST sends data in the request body โ€” not visible in URLs. Always use POST for sensitive data (login, payment, registration).
๐Ÿข Security 101 โ€” every company's code review catches this
L4 Analyze
Q11

A developer adds srcset to images but doesn't include sizes. What happens?

  1. Images don't load at all
  2. The browser defaults to assuming the image is 100vw (full viewport width) and may download an oversized image for smaller containers
  3. The smallest image is always loaded
  4. srcset is ignored
โœ… B
๐Ÿ“– Without sizes, the browser assumes the image fills 100% of the viewport. For a 300px sidebar image on a 1440px screen, it downloads the 1440px variant. sizes="300px" tells the browser the actual display size. (A)(C)(D) Incorrect.
๐Ÿข Google Core Web Vitals โ€” LCP optimization
L4 Analyze

Level 5 โ€” Evaluate โญโญโญ

Q12

A teammate argues: "We should use only JavaScript for form validation and skip HTML5 validation attributes." What's your response?

  1. "Agreed โ€” JavaScript is more powerful"
  2. "HTML5 validation provides a first layer that works without JS, is accessible, and is faster. JS should add a second layer for complex rules. Use both."
  3. "HTML5 validation is enough, no need for JavaScript"
  4. "Both are unnecessary if we validate on the server"
โœ… B
๐Ÿ“– Defense in depth: HTML5 validates without JS (works if JS fails/blocked). JS handles complex rules (comparing fields, async checks). Server validates everything again (never trust client). All three layers are needed. (A) Ignores accessibility/JS-off. (C) Complex rules need JS. (D) Server-only means bad UX.
๐Ÿข Architecture interview question at product companies
L5 Evaluate
Q13

A table without <caption>, scope, or <thead>/<tbody> looks identical to a properly structured table. Should the team refactor it?

  1. No โ€” visual correctness is sufficient
  2. Yes โ€” screen readers can't navigate the table, violating WCAG; search engines can't understand the data; and long tables won't have proper scroll behavior
  3. Only if the table has more than 10 rows
  4. Only if the client specifically requests accessibility
โœ… B
๐Ÿ“– Accessibility is not feature-request-based โ€” it's a compliance requirement. caption provides context, scope enables cell-header association, and thead/tbody enables proper printing and scrolling. (A)(C)(D) Miss legal and UX implications.
๐Ÿข Accessibility audit at any enterprise
L5 Evaluate

Level 6 โ€” Create โญโญโญ

Q14

You're designing a flight booking form for a startup. Which combination of HTML5 elements best handles: departure date (no past dates), number of passengers (1-9), and cabin class selection?

  1. Three <input type="text"> fields
  2. <input type="date" min="today"> + <input type="number" min="1" max="9"> + <select> with Economy/Business/First
  3. A single <textarea> asking users to type all details
  4. Three <input type="radio"> groups
โœ… B
๐Ÿ“– Each control matches its data type: date picker prevents past dates natively, number input enforces 1-9 range, select gives fixed options. (A) No validation. (C) Unstructured. (D) Radio is wrong for date/number.
๐Ÿข Form design at MakeMyTrip, Cleartrip
L6 Create
Q15

A form requires the user to enter a GST number in the format: 22AAAAA0000A1Z5 (2 digits, 5 letters, 4 digits, 1 letter, 1 digit, 1 letter, 1 digit). Which HTML achieves this?

  1. <input type="text" maxlength="15">
  2. <input type="text" required pattern="\d{2}[A-Z]{5}\d{4}[A-Z]\d[A-Z]\d" title="Valid GST: 22AAAAA0000A1Z5">
  3. <input type="gst">
  4. <input type="number" minlength="15">
โœ… B
๐Ÿ“– The regex \d{2}[A-Z]{5}\d{4}[A-Z]\d[A-Z]\d matches the GST format exactly. title shows a hint on validation failure. (A) No format check. (C) No such type. (D) Number can't contain letters.
๐Ÿข Every Indian B2B fintech form
L6 Create
Section 7

Chapter Summary

Concept Mind Map

Mind Map
                    ADVANCED HTML5 & RESPONSIVE DESIGN
                                โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      Lists       Links      Images      Tables      Forms
        โ”‚           โ”‚           โ”‚           โ”‚           โ”‚
   โ”œโ”€ ul (unord)  โ”œโ”€ href     โ”œโ”€ srcset   โ”œโ”€ caption  โ”œโ”€ fieldset/legend
   โ”œโ”€ ol (order)  โ”œโ”€ target   โ”œโ”€ sizes    โ”œโ”€ scope    โ”œโ”€ input types (15+)
   โ”œโ”€ dl (defn)   โ”œโ”€ rel      โ”œโ”€ lazy     โ”œโ”€ colspan  โ”œโ”€ select/datalist
   โ””โ”€ nesting     โ”œโ”€ mailto   โ”œโ”€ alt      โ”œโ”€ rowspan  โ”œโ”€ textarea
                  โ”œโ”€ tel      โ”œโ”€ figure   โ”œโ”€ thead    โ”œโ”€ validation attrs
                  โ””โ”€ download โ””โ”€ figcaptionโ””โ”€ tfoot   โ””โ”€ file upload

Key Takeaways for Industry

  • Forms are the #1 user interaction point โ€” get them wrong and users leave. HTML5 gives you 15+ input types and native validation for free. Use them.
  • Images must be responsive โ€” srcset + sizes + loading="lazy" is the industry standard. A 2MB image on 4G is unacceptable.
  • Tables are for data, not layout โ€” and accessible tables need caption, scope, thead/tbody/tfoot. No exceptions.
  • Always add rel="noopener noreferrer" to target="_blank" links. Security audits flag this everywhere.
  • HTML5 validation is your first defense line โ€” required, pattern, min/max validate without JavaScript. JS adds the second layer. Server adds the third.

Quick Reference โ€” HTML5 Input Types

TYPE           KEYBOARD    VALIDATES         USE CASE
text           ABC         No                Name, address
email          @ keyboard  Email format      Email fields
tel            Dial pad    No (use pattern)  Phone number
number         Numeric     min/max/step      Age, quantity
date           Date picker Date format       DOB, travel date
search         ABC + โœ•     No                Search bar
url            ABC + .com  URL format        Website field
color          Color wheel Valid hex          Theme picker
range          Slider      min/max           Volume, rating
file           File picker accept filter     Upload documents
password       ABC (dots)  No                Login
hidden         None        No                Form tokens

"What to Google Next"

  1. ๐Ÿ” "HTML5 form validation API MDN" โ€” Deep dive into checkValidity() and setCustomValidity()
  2. ๐Ÿ” "srcset and sizes explained" โ€” Master responsive images
  3. ๐Ÿ” "WCAG 2.1 table accessibility" โ€” Learn enterprise-grade table accessibility
Section 8

Interview Preparation

10 Frequently Asked Interview Questions

1. What is the difference between <select> and <datalist>?

<select> shows a fixed dropdown โ€” users MUST pick from the options. <datalist> provides suggestions for an <input> โ€” users can type freely OR pick a suggestion. Datalist is ideal for large lists (like 7,000+ railway stations) where a dropdown is impractical.

2. What does enctype="multipart/form-data" do?

It changes how form data is encoded when submitted. Default encoding (application/x-www-form-urlencoded) can't handle files. multipart/form-data encodes each field as a separate "part" โ€” required for file uploads. Without it, <input type="file"> sends only the filename, not the file content.

3. Explain the difference between GET and POST methods.

GET appends data to the URL (?key=value) โ€” visible, cacheable, limited to ~2KB. Use for search, filters. POST sends data in the request body โ€” hidden from URL, no size limit. Use for login, registration, file uploads, payments. Never use GET for sensitive data.

4. What is srcset and why is it important?

srcset provides multiple image sources for different screen sizes/resolutions. The browser picks the best one โ€” serving a 400px image on mobile and a 1200px image on desktop. Saves bandwidth, improves load time, and is a Google Core Web Vitals factor (LCP).

5. How do you make a table accessible for screen readers?

Use <caption> for the table title, <th> with scope="col"/scope="row" for headers, and <thead>/<tbody>/<tfoot> for grouping. This lets screen readers announce "Row 3, Column Price: โ‚น2,499" instead of just "โ‚น2,499."

6. What is the pattern attribute used for?

pattern specifies a regex that the input must match. Example: pattern="[6-9]\d{9}" validates Indian mobile numbers. Combined with title, it shows a hint on validation failure. Works without JavaScript โ€” native browser validation.

7. What is the difference between colspan and rowspan?

colspan="3" makes a cell span 3 columns horizontally. rowspan="2" makes a cell span 2 rows vertically. Common use: "Suite" room type spanning price + capacity columns, or a company name spanning all rows of its employees.

8. What happens if you omit the name attribute on a form input?

The input's data is NOT sent to the server when the form is submitted. name is the key in the key-value pair. Without it, the field is invisible to the backend โ€” a very common bug in student projects and even production code.

9. Explain loading="lazy" on images and iframes.

It defers loading until the element is near the viewport (user scrolls close). Reduces initial page weight dramatically โ€” a page with 50 product images might only load 8 initially. Native HTML attribute โ€” no JavaScript needed. Supported in all modern browsers.

10. When should you use <figure> and <figcaption>?

Use them when an image (or diagram, code listing, video) has a caption that explains it. <figure> wraps the media + caption as a semantic unit. Screen readers announce the caption as part of the image. Better than a random <p> below an <img>.

GitHub Portfolio Tip ๐Ÿ’ผ

Build and push: A complete "Hotel Booking" or "Train Booking" form with all HTML5 input types, validation, responsive images, and accessible tables. Include a README documenting which HTML5 features you used and why. This demonstrates form mastery โ€” the #1 skill companies test in HTML interviews.

Certification Path ๐ŸŽ“

  • โœ… freeCodeCamp โ€” Responsive Web Design: HTML Forms section
  • โœ… Google Developers โ€” Web Accessibility course (forms & tables)
  • โœ… MDN Web Docs โ€” HTML Forms Guide (interactive tutorials)