DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. HTML Interview Questions, Answered Against the Living Standard
XLinkedInReddit
EasyFrontend Engineering

HTML Interview Questions, Answered Against the Living Standard

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.

R
rahulrana1
8 min read·0
Table of Contents
  • Fundamentals
  • 1. What does semantic HTML actually buy you?
  • 2. Block or inline, and does it still matter?
  • 3. What is the difference between an attribute and a property?
  • Forms, where most of the real questions live
  • 4. Why use a <form> if you are going to call preventDefault() anyway?
  • 5. What is the label element really doing?
  • 6. Which input type should a phone number use?
  • Loading and performance
  • 7. defer or async?
  • 8. Why do images need width and height if CSS sizes them?
  • 9. What does loading="lazy" cost you?
  • Questions for senior and staff candidates
  • 10. How does the browser recover from broken HTML?
  • 11. When is a custom element the right answer?
  • 12. What is the accessibility tree, and when does it diverge from the DOM?
  • 13. What would you check first on a page that scores badly on Core Web Vitals?
  • How to prepare
  • Sources
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 <div> with a click handler, and a candidate who reaches for a <button>, 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 <button> arrives with a role, keyboard activation on both Enter and Space, focusability, and a disabled state the browser enforces. A <div onclick> arrives with none of it. You can bolt it all on, and the version people write usually misses something.

<!-- 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>
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, 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 <div> inside a <p> does not produce a nested div. The parser closes the paragraph first, because a <p> 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.

// <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 <form> 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.

<!-- 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, and very few candidates have read it.

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.

stopskeeps goingkeeps goingmay run before or afteralways before, in orderParserbuilds the DOMclassicblocks parsingasyncruns on arrivaldeferruns before DOMContentLoadedDOMContentLoaded
Three scripts, three behaviours. The blocking one is why "scripts go at the bottom" became folklore.

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

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 - the normative reference for content models, parsing and form behaviour
  • HTML Standard, Parsing - specified error recovery
  • HTML Standard, Autofill - the autocomplete token list
  • MDN, the input element - types and their behaviours
  • web.dev, Optimize Cumulative Layout Shift - why images need dimensions

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • Fundamentals
  • 1. What does semantic HTML actually buy you?
  • 2. Block or inline, and does it still matter?
  • 3. What is the difference between an attribute and a property?
  • Forms, where most of the real questions live
  • 4. Why use a &lt;form&gt; if you are going to call preventDefault() anyway?
  • 5. What is the label element really doing?
  • 6. Which input type should a phone number use?
  • Loading and performance
  • 7. defer or async?
  • 8. Why do images need width and height if CSS sizes them?
  • 9. What does loading="lazy" cost you?
  • Questions for senior and staff candidates
  • 10. How does the browser recover from broken HTML?
  • 11. When is a custom element the right answer?
  • 12. What is the accessibility tree, and when does it diverge from the DOM?
  • 13. What would you check first on a page that scores badly on Core Web Vitals?
  • How to prepare
  • Sources

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.