HTML interview questions

18 questions from the HTML Fundamentals: Structure, Forms and Accessibility course, each with the correct answer and an explanation. Try to answer before you open the answer.

Module 1: Getting Started

1. Which element holds the content visitors actually see?

  1. <head>
  2. <!DOCTYPE html>
  3. <body>
  4. <footer>
Show answer

Answer: <body>

`<body>` contains everything rendered on the page; `<head>` is metadata for the browser.

Lesson: Document Structure

Module 2: Text & Structure

2. Which tag carries semantic meaning, not just visual style?

  1. <b>
  2. <i>
  3. <small>
  4. <strong>
Show answer

Answer: <strong>

`<strong>` communicates importance to assistive tech; `<b>` and `<i>` are purely visual.

Lesson: Text Formatting

Module 3: Links & Media

3. Which attribute shows built-in play/pause controls?

  1. controls
  2. autoplay
  3. loop
  4. muted
Show answer

Answer: controls

`controls` adds the browser's default playback UI.

Lesson: Audio & Video

4. Which attribute defers loading of offscreen images?

  1. loading="lazy"
  2. decoding="sync"
  3. rel="preload"
  4. async
Show answer

Answer: loading="lazy"

Native lazy loading waits until the image is near the viewport.

Lesson: Responsive Images: picture, srcset & Lazy Loading

Module 4: Lists & Tables

5. Which tag defines a header cell in a table?

  1. <td>
  2. <th>
  3. <tr>
  4. <caption>
Show answer

Answer: <th>

`<th>` marks a header cell — bold and centered by default, and meaningful to assistive tech.

Lesson: Tables

Module 5: Forms

6. Which attribute makes a field mandatory before submit?

  1. placeholder
  2. readonly
  3. required
  4. autofocus
Show answer

Answer: required

`required` blocks form submission until that field has a value.

Lesson: Basic Validation

Module 6: Semantic HTML & Accessibility

7. What should a purely decorative image's alt attribute be?

  1. Omitted entirely
  2. A long description
  3. The page title
  4. An empty string alt=""
Show answer

Answer: An empty string alt=""

`alt=""` tells screen readers to skip it silently, which is correct for purely decorative images.

Lesson: Alt Text & ARIA

Module 7: Meta & Layout Helpers

8. What is a common real-world use of an iframe?

  1. Embedding a YouTube video or map
  2. Styling text
  3. Validating a form
  4. Creating a table of contents
Show answer

Answer: Embedding a YouTube video or map

iframes commonly embed third-party widgets like videos, maps and payment forms.

Lesson: iframes

Module 8: Modern HTML

9. What's true about content inside a `<template>` tag?

  1. It renders immediately like normal HTML
  2. It's inert until JavaScript clones it into the page
  3. It's invalid HTML
  4. It is rendered twice
Show answer

Answer: It's inert until JavaScript clones it into the page

Template content is parsed but stays hidden and inactive until explicitly cloned via script.

Lesson: Templates & Custom Elements

Module 9: Best Practices

10. Which is a common beginner HTML mistake?

  1. Using semantic tags like <nav>
  2. Adding alt text to images
  3. Wrapping every element in generic <div> tags
  4. Writing valid, closed tags
Show answer

Answer: Wrapping every element in generic <div> tags

Overusing generic `<div>` tags instead of semantic elements is a classic beginner habit that hurts accessibility and SEO.

Lesson: Common Beginner Mistakes

11. Which element holds the visible page content?

  1. <head>
  2. <meta>
  3. <body>
  4. <title>
Show answer

Answer: <body>

The body contains everything users see.

Lesson: Common Beginner Mistakes

12. Which tag carries semantic emphasis?

  1. <b>
  2. <i>
  3. <font>
  4. <strong>
Show answer

Answer: <strong>

strong signals importance to assistive technology.

Lesson: Common Beginner Mistakes

13. What should a decorative image's alt be?

  1. alt=""
  2. A long description
  3. Omitted
  4. The file name
Show answer

Answer: alt=""

An empty alt tells screen readers to skip it.

Lesson: Common Beginner Mistakes

14. Which attribute binds a label to an input?

  1. name
  2. for (matching the input id)
  3. class
  4. href
Show answer

Answer: for (matching the input id)

label for matches the input's id.

Lesson: Common Beginner Mistakes

15. Why re-validate form data on the server?

  1. HTML validation is slow
  2. Servers ignore HTML
  3. Browser validation can be bypassed
  4. It is required by the spec
Show answer

Answer: Browser validation can be bypassed

Never trust client-side checks alone.

Lesson: Common Beginner Mistakes

16. Which tag makes mobile browsers use the real screen width?

  1. meta charset
  2. link rel icon
  3. base
  4. meta viewport
Show answer

Answer: meta viewport

width=device-width, initial-scale=1 enables responsive layouts.

Lesson: Common Beginner Mistakes

17. What is true of `<template>` content?

  1. It is inert until JavaScript clones it
  2. It renders immediately
  3. It is invalid HTML
  4. It runs scripts first
Show answer

Answer: It is inert until JavaScript clones it

Templates are parsed but not rendered.

Lesson: Common Beginner Mistakes

18. Which is a good SEO basic in HTML?

  1. Many h1 tags
  2. A unique title and one clear h1
  3. Empty alt on all images
  4. Duplicate titles
Show answer

Answer: A unique title and one clear h1

Unique titles and a logical heading structure help search engines.

Lesson: Common Beginner Mistakes

← Back to the course