---
title: "HTML Interview Questions, Answered Against the Living Standard"
description: "Thirteen questions, from why a button beats a div to what the accessibility tree does that the DOM does not. Every claim checkable against the WHATWG standard."
canonical_url: https://devprep.co/articles/html-interview-questions
md_url: https://devprep.co/articles/html-interview-questions.md
last_updated: 2026-11-19
access: public
---

# HTML Interview Questions, Answered Against the Living Standard

> [!NOTE]
> The short answer
>
> HTML questions sort candidates faster than any other frontend topic, because almost nobody prepares for them. The ones that separate people are not trivia. They are the questions where the browser does something you did not write: it builds an accessibility tree, it repairs your markup, it decides what to load first. Knowing why is the whole interview.

There is a reason HTML keeps appearing in frontend interviews even at senior level, and it is not nostalgia. A candidate who reaches for a `` with a click handler, and a candidate who reaches for a ``, are telling you different things about how much of the platform they have had to debug.

This runs from the fundamentals to the questions that get asked of staff candidates. Every claim here is checkable against the HTML Living Standard or MDN, both linked at the end.

## Fundamentals

### 1. What does semantic HTML actually buy you?

The weak answer is "it is better for SEO and accessibility". True, but it does not show you know the mechanism. The mechanism is that the browser builds a second tree alongside the DOM, the accessibility tree, and the element you choose decides what goes in it.

A `` arrives with a role, keyboard activation on both Enter and Space, focusability, and a disabled state the browser enforces. A `` arrives with none of it. You can bolt it all on, and the version people write usually misses something.

```html
<!-- What you have to write to catch up with <button>, and this is
     still missing the disabled state and the focus ring. -->
<div
  role="button"
  tabindex="0"
  onclick="save()"
  onkeydown="if (event.key === 'Enter' || event.key === ' ') save()"
>
  Save
</div>

<!-- All of the above, for free, and it submits a form. -->
<button type="button" onclick="save()">Save</button>
```

> [!TIP]
> Where people get stuck
>
> Stopping at "semantics help screen readers". The sharper answer names a behaviour you would otherwise reimplement: Space activates a button but not a link, Enter activates both, and a native button inside a form submits it unless you set `type="button"`. That last one is a real bug people ship: a button in a form with no explicit type defaults to `submit` per the [HTML Living Standard](https://html.spec.whatwg.org/multipage/form-elements.html#attr-button-type), which is why "my save button reloads the page" is such a common complaint.

### 2. Block or inline, and does it still matter?

It matters less than it used to, and saying so is a good answer. CSS `display` overrides the default, so the real distinction today is the _content model_: what the HTML parser will let you nest.

Putting a `` inside a `` does not produce a nested div. The parser closes the paragraph first, because a `` may only contain phrasing content. You end up with two siblings and an empty paragraph, and your CSS stops matching. This is the kind of thing that looks like a framework bug for an hour.

### 3. What is the difference between an attribute and a property?

The attribute is what is in the markup. The property is what lives on the DOM object. They are synced at parse time and then drift.

```javascript
// <input id="name" value="Ada">
const input = document.getElementById("name");

input.value;                      // "Ada"
input.getAttribute("value");      // "Ada"

// The user types "Grace".
input.value;                      // "Grace"  -- the live state
input.getAttribute("value");      // "Ada"    -- the initial state

// This is why resetting a form restores "Ada": the attribute is the
// default value, and the property is the current one.
```

The same split explains `checked` versus `defaultChecked`, and it is why React calls the markup one `defaultValue`.

## Forms, where most of the real questions live

### 4. Why use a `` if you are going to call `preventDefault()` anyway?

Because a form is not just a submission mechanism. Wrapping fields in one gives you Enter-to-submit, native validation, autofill grouping that password managers understand, and a `submit` event that fires however the user triggered it. A collection of inputs and a button gives you none of those, and the gap shows up first for keyboard and mobile users.

### 5. What is the `label` element really doing?

Two things, and people usually name only the first. It gives the control an accessible name, and it extends the hit area: clicking the label focuses or toggles the control. On a checkbox that is the difference between a 16px target and a comfortable one, which matters on a phone.

```html
<!-- Explicit: for matches the control's id. Works anywhere in the page. -->
<label for="email">Email</label>
<input id="email" type="email" name="email" autocomplete="email">

<!-- Implicit: the control is inside. No id needed. -->
<label>
  <input type="checkbox" name="terms">
  I accept the terms
</label>

<!-- A placeholder is not a label. It disappears on focus, fails
     contrast requirements in most designs, and is not announced
     reliably as a name. -->
<input placeholder="Email">
```

### 6. Which input type should a phone number use?

A question that sounds trivial and is not. `type="number"` is wrong: it is for numeric _quantities_, so it strips leading zeros, shows a spinner, and rejects the plus sign and spaces people type. `type="tel"` is right: it brings up the phone keypad on mobile and applies no parsing.

The follow-up is autocomplete. `autocomplete="tel"` lets the browser fill it, and on a checkout form the autocomplete tokens are worth real conversion. The full token list is in the [autofill section of the standard](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill), and very few candidates have read it.

> [!WARNING]
> A trap worth knowing
>
> Setting `autocomplete="off"` on a password field does not reliably stop password managers, and has not for years. Browsers deliberately ignore it there, because managers improve security on balance. If an interviewer asks how to disable autofill on a login form, the correct answer is that you largely cannot, and should not want to.

## Loading and performance

### 7. `defer` or `async`?

Both download the script without blocking the parser. The difference is when it runs and in what order.

```diagram
direction: lr
width: 720
caption: Three scripts, three behaviours. The blocking one is why "scripts go at the bottom" became folklore.

nodes:
  - { id: p,    label: Parser,        note: builds the DOM }
  - { id: cls,  label: classic,       note: blocks parsing, style: warn }
  - { id: asy,  label: async,         note: runs on arrival }
  - { id: def,  label: defer,         note: runs before DOMContentLoaded, style: accent }
  - { id: dcl,  label: DOMContentLoaded, style: store }

edges:
  - [p, cls, "stops"]
  - [p, asy, "keeps going"]
  - [p, def, "keeps going", hot]
  - [asy, dcl, "may run before or after"]
  - [def, dcl, "always before, in order", hot]
```

`defer` preserves document order and runs after parsing, which is what you want for your own application code. `async` runs whenever it arrives, in whatever order, which suits an independent third-party tag and nothing else. A script with dependencies marked `async` is a race condition waiting for a slow network.

### 8. Why do images need `width` and `height` if CSS sizes them?

Because the browser needs the aspect ratio before the image arrives, to reserve space. Without it the page reflows when each image loads, which is the single most common cause of a bad Cumulative Layout Shift score. Modern browsers compute `aspect-ratio` from the two attributes, so you keep your CSS sizing and lose the shift. [web.dev's CLS guidance](https://web.dev/articles/optimize-cls) puts "images without dimensions" first on its list of causes.

### 9. What does `loading="lazy"` cost you?

Put it on the wrong image and it costs you your Largest Contentful Paint. A lazily loaded image is not fetched until the browser decides it is near the viewport, which for an above-the-fold hero means a deliberate delay on the exact element LCP measures. The rule: lazy-load everything below the fold, never the hero, and give the hero `fetchpriority="high"` instead.

## Questions for senior and staff candidates

### 10. How does the browser recover from broken HTML?

Worth knowing because the answer is "very specifically". HTML parsing is not lenient in a vague sense; the error handling is fully specified, which is why every browser builds the same wrong tree from the same bad markup. Unclosed tags, misnested elements and stray end tags all have defined recovery rules in the [parsing section of the standard](https://html.spec.whatwg.org/multipage/parsing.html).

The practical consequence: "it renders fine" is not evidence your markup is valid, only that the recovery happened to match your intent. Two parsers agreeing does not mean you were right.

### 11. When is a custom element the right answer?

When the thing must work outside your framework: a widget embedded in pages you do not control, or a design system consumed by teams on different stacks. Inside a single React application a custom element is usually friction, because you lose the framework's event and prop handling and gain a second component model.

The follow-up worth preparing is Shadow DOM's cost: style isolation is the feature, and it is also the problem, since your global design tokens do not cross the boundary unless you pass them as CSS custom properties, which do inherit through it.

### 12. What is the accessibility tree, and when does it diverge from the DOM?

It is the structure assistive technology actually reads, derived from the DOM plus roles, states and computed styles. It diverges constantly. `display: none` removes a node from it. `aria-hidden="true"` removes it while leaving it visible. An element with `role="presentation"` keeps its children but loses its own semantics.

The failure this explains: a visually hidden element implemented with `display: none` is hidden from screen readers too, which is the opposite of what a "visually hidden" utility class is for. The correct implementation clips the element rather than removing it.

### 13. What would you check first on a page that scores badly on Core Web Vitals?

Answer with an order, not a list. Find the LCP element first, because until you know which element it is you are guessing. Then ask whether it is discoverable in the initial HTML: an LCP image inserted by JavaScript cannot be preloaded by the browser's scanner, and that one fact explains a large share of bad scores on otherwise fast sites.

## How to prepare

Open the standard once. Not to read it through, but so it stops being abstract: pick the section on an element you use daily and read its content model and its attributes. Most candidates have never done this, and it shows in the specificity of their answers.

Then take one page you have built and run it through a keyboard only. No mouse. The elements you cannot reach are the ones your markup got wrong, and that exercise will teach you more about semantic HTML than any list of questions, this one included.

## Sources

- [HTML Living Standard, WHATWG](https://html.spec.whatwg.org/multipage/) - the normative reference for content models, parsing and form behaviour
- [HTML Standard, Parsing](https://html.spec.whatwg.org/multipage/parsing.html) - specified error recovery
- [HTML Standard, Autofill](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) - the autocomplete token list
- [MDN, the input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) - types and their behaviours
- [web.dev, Optimize Cumulative Layout Shift](https://web.dev/articles/optimize-cls) - why images need dimensions

---

Public pages are mirrored here in full. Premium pages are listed with their summary only — the gated body stays behind server-side entitlement checks.
