Episode 1 — Fundamentals / 1.5 — Semantic HTML and Browser Rendering

Interview Questions: Semantic HTML & Browser Rendering

Practice questions with model answers for browser rendering, CLS, semantic elements, SEO, accessibility, ARIA, responsive images, and forms — topics commonly asked in front-end and full-stack interviews.

How to use this material (instructions)

  1. Read lessons in orderREADME.md, then 1.5.a1.5.i.
  2. Practice out loud — aim for 1–2 minutes per question, then compare to the model answer.
  3. Structure answers — definition → example → trade-off / accessibility note.
  4. Pair with exercises1.5-Exercise-Questions.md.
  5. Quick review1.5-Quick-Revision.md.

Beginner (Q1–Q8)

Q1. Walk through the browser rendering pipeline at a high level.

Why interviewers ask: Tests whether you understand the fundamental process that turns code into pixels — the foundation of all front-end performance work.

Model answer:

The browser receives HTML bytes and parses them into the DOM (Document Object Model). CSS is parsed into the CSSOM (CSS Object Model). The engine combines DOM + CSSOM into a render tree — only elements that will actually be painted (elements with display: none are excluded). Then:

  1. Layout (reflow) — computes geometry: positions, sizes, line breaks for every visible box
  2. Paint — fills pixels: text, colors, borders, shadows, images
  3. Composite — assembles painted layers (GPU-accelerated) into the final frame

JavaScript can mutate the DOM or CSSOM at any point, potentially forcing the browser to repeat downstream stages (layout → paint → composite).

HTML ──► DOM ──┐
               ├──► Render Tree ──► Layout ──► Paint ──► Composite ──► Pixels
CSS  ──► CSSOM ┘

Q2. What is the difference between reflow and repaint?

Why interviewers ask: Shows you understand rendering costs and can reason about performance trade-offs.

Model answer:

TermWhat changesExample trigger
Reflow (layout)Geometry — positions, sizes, line breaksChanging width, height, padding; inserting/removing DOM nodes
RepaintVisual appearance — no geometry changeChanging color, background-color, visibility on a same-sized box

Some changes trigger both — if you change border-width, geometry changes (reflow) and pixels change (repaint). Reflow is generally more expensive because it can cascade to many nodes. The cheapest visual changes target compositor-only properties like transform and opacity, which can skip both layout and paint entirely.


Q3. What is CLS and why does it matter?

Why interviewers ask: CLS is a Core Web Vital — interviewers want to know you care about user experience, not just functionality.

Model answer:

Cumulative Layout Shift (CLS) measures unexpected visual movement during the page lifecycle. When elements shift after the user has started reading or aiming for a click target, they lose trust and may misclick.

Common causes:

  • Images/iframes without reserved dimensions (intrinsic size arrives late → content jumps)
  • Late-loading web fonts causing FOIT/FOUT reflow
  • Dynamically injected banners or ads above existing content
  • Content inserted by client-side JS after initial render

Fixes: reserve space with width/height or aspect-ratio, use skeleton placeholders, set font-display strategies, and insert dynamic content below the viewport or in pre-sized containers.


Q4. Why use semantic elements like <main> and <nav> instead of only <div>?

Why interviewers ask: Separates candidates who understand accessibility and document structure from those who only think visually.

Model answer:

Native semantic elements expose roles and landmarks to the accessibility API so assistive technologies (screen readers, voice control) can present predictable navigation. A screen reader user can open a landmarks rotor and jump directly to "main content" or "navigation" — impossible with anonymous div soup.

BenefitHow semantics help
AccessibilityLandmarks, headings, and roles let AT users navigate efficiently
SEOSearch engines segment boilerplate from primary content
MaintainabilityIntent is clear in markup — easier code review and onboarding
ConsistencyStandard elements enforce consistent structure across pages

div remains fine for styling hooks and layout wrappers — it just carries no semantic weight.


Q5. What is the first rule of ARIA?

Why interviewers ask: Verifies you understand that ARIA is a supplement, not a replacement for proper HTML.

Model answer:

If you can use a native HTML element with the needed semantics and behavior, do not use ARIA instead. Native controls like <button>, <a href>, <input> ship built-in keyboard handling, focus management, naming, and state behavior. Recreating all of that with <div role="button" tabindex="0"> is fragile and easy to get wrong — you must manually handle Enter, Space, focus styles, and disabled states.

Second rule: Do not change native semantics unless you have a specific reason — <button role="heading"> is never correct.


Q6. What is the difference between <title> and <h1>?

Why interviewers ask: Tests understanding of document metadata vs on-page structure.

Model answer:

<title><h1>
LocationInside <head> — not visible on pageInside <body> — visible on page
PurposeLabels the document in tabs, bookmarks, and search result snippetsLabels the primary topic of the visible content
SEO roleStrong relevance signal for search rankingStructure signal — communicates main topic to crawlers
Can differ?Yes — title may include site name; h1 is page-specificYes — they serve different audiences

In many sites they are similar, but they are not interchangeable. A page can have a <title> of "Shipping Policy | Acme Store" and an <h1> of "Shipping Policy" — different strings, both correct.


Q7. Why do we still validate on the server if HTML5 validation exists?

Why interviewers ask: The most fundamental security concept in web development — never trust the client.

Model answer:

Client-side validation (HTML5 attributes like required, pattern, min/max, and custom JavaScript) improves UX by giving fast feedback and reducing bad requests. But the client is untrusted — users can:

  • Open DevTools and remove required attributes
  • Craft raw HTTP requests with curl or Postman
  • Disable JavaScript entirely
  • Tamper with hidden fields (prices, role flags)

Server-side validation enforces authorization (can this user do this?), business rules (is the price correct?), data integrity (does this reference exist?), and security (SQL injection, XSS). The server is the source of truth — client validation is a courtesy, not a gate.


Q8. What is the critical rendering path?

Why interviewers ask: Shows you can reason about initial load performance.

Model answer:

The critical rendering path (CRP) is the minimum sequence of work the browser must complete to render the first meaningful pixels above the fold:

  1. Parse critical HTML → build DOM
  2. Parse critical CSS → build CSSOM (CSS is render-blocking)
  3. Combine → render tree
  4. Layout → compute geometry
  5. Paint → first pixels visible

Optimization levers:

  • Inline or prioritize critical CSS for above-the-fold content
  • Use defer or async on scripts to avoid parser-blocking
  • Minimize render-blocking resources (fewer CSS files, code-split JS)
  • Ship right-sized images and reserve space to avoid CLS

Intermediate (Q9–Q15)

Q9. Explain srcset and sizes on an <img>.

Why interviewers ask: Responsive images are table stakes for modern front-end — this tests practical knowledge.

Model answer:

srcset lists image candidates with descriptors:

  • w descriptors provide intrinsic pixel widths (e.g. hero-400.jpg 400w, hero-800.jpg 800w)
  • x descriptors provide DPR targets (e.g. icon@2x.png 2x)

sizes tells the browser how wide the image will render at different viewport breakpoints — for example (max-width: 600px) 100vw, 50vw means "full viewport on mobile, half viewport on desktop."

The browser combines sizes + viewport width + device pixel ratio to pick the best candidate from srcset — all before layout completes. This avoids downloading an oversized image while keeping things sharp on retina screens.

<img
  src="hero-800.jpg"
  srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, 50vw"
  width="1200" height="675"
  alt="Product showcase"
/>

Q10. When would you use <picture> instead of srcset alone?

Why interviewers ask: Tests whether you understand the distinction between resolution switching and art direction/format negotiation.

Model answer:

Use <picture> for two scenarios that srcset alone cannot handle:

ScenarioWhy <picture>
Format negotiationServe AVIF → WebP → JPEG fallback based on browser support
Art directionServe different crops or compositions at breakpoints (e.g. wide landscape on desktop, tight portrait on mobile)

A single <img srcset sizes> is enough when you only need resolution adaptation — the same image at different pixel densities.

<picture>
  <source type="image/avif" srcset="hero.avif" />
  <source type="image/webp" srcset="hero.webp" />
  <img src="hero.jpg" alt="…" width="1200" height="675" />
</picture>

The browser picks the first <source> it can decode. The <img> at the end is the mandatory fallback.


Q11. How should heading levels be structured for accessibility?

Why interviewers ask: Heading structure is the most common accessibility mistake on production sites.

Model answer:

Headings should form a logical outline that mirrors the document's content hierarchy:

h1  Page topic (one per page in most sites)
├─ h2  Major section A
│  ├─ h3  Subsection A.1
│  └─ h3  Subsection A.2
└─ h2  Major section B

Rules:

  • Do not skip levels — jumping from h2 to h5 breaks the mental model for screen reader users who navigate by headings
  • Do not pick heading tags for font size — that is CSS's job
  • Every <section> should ideally have a heading — it is part of the spec's intent
  • In component-based apps, nested components should use deeper heading levels consistently (cards inside a section use h3, not another h2)

Screen reader users scan pages via a headings list (rotor) — a clean outline lets them jump to the section they need in seconds.


Q12. What are rel="sponsored" and rel="ugc" for?

Model answer:

They classify outbound links for search engines and platform trust:

rel valueMeaning
sponsoredPaid, partner, or affiliate links — the link exists because of a commercial relationship
ugcUser-generated content links — comments, forum posts, wiki edits
nofollowGeneral hint: do not pass ranking credit (older, broader signal)

These communicate intent honestly to search systems. Using them correctly protects your site's trust profile and avoids deceptive linking patterns. They complement security-focused rels like noopener and noreferrer.


Q13. Explain the difference between defer and async on a <script> tag.

Why interviewers ask: Parser-blocking scripts are a top performance problem — this tests practical knowledge.

Model answer:

AttributeDownloadExecutionOrder guaranteed?
(none)Blocks HTML parsingImmediately after downloadYes (sequential)
asyncParallel to parsingImmediately when download completesNo — whichever finishes first runs first
deferParallel to parsingAfter HTML parsing completes, before DOMContentLoadedYes — document order preserved

When to use each:

  • defer — most scripts; you want DOM ready and execution order matters (e.g. app bundle + libraries)
  • async — independent scripts where order does not matter (e.g. analytics, ads)
  • Neither — rare; only when the script must execute inline during parsing (legacy patterns)

Q14. What does aria-live do, and when would you use it?

Why interviewers ask: Dynamic content updates are a blind spot in many applications — tests awareness of real-time accessibility.

Model answer:

aria-live marks a region whose content may update dynamically. When the content changes, screen readers announce the change without the user needing to navigate to that element.

ValueBehavior
politeWaits for the user to finish current task before announcing
assertiveInterrupts immediately — use sparingly (errors, urgent alerts)
offNo announcements (default)

Use cases:

  • Form validation error messages (assertive)
  • Toast notifications (polite)
  • Live search result counts (polite)
  • Chat messages in a messaging app (polite)

Pitfall: Overusing aria-live creates noisy, overwhelming experiences — only announce what the user needs to know.


Q15. Compare WebP and AVIF image formats.

Model answer:

WebPAVIF
CompressionGood — typically 25–35% smaller than JPEGOften better — 30–50% smaller than JPEG
Browser supportVery broad (all modern browsers)Growing — most modern browsers, some older gaps
Encode speedFastSlower (higher computational cost)
FeaturesLossy + lossless, transparency, animationLossy + lossless, transparency, HDR, wide color gamut
Best forGeneral-purpose replacement for JPEG/PNGMaximum compression when encode time is acceptable

Strategy: Use <picture> with AVIF as first source, WebP as second, JPEG/PNG as final fallback. This serves the smallest file to capable browsers while maintaining universal compatibility.


Advanced / Scenario (Q16–Q20)

Q16. A page janks when resizing the window. What might be happening in the pipeline?

Why interviewers ask: Tests debugging mindset and rendering pipeline knowledge applied to a real symptom.

Model answer:

Window resize triggers layout for many elements — the browser must recompute geometry for everything affected by viewport-relative units, percentage widths, flexbox, and grid.

What makes it worse:

  • Layout thrashing — event handlers read geometry (getBoundingClientRect()) after writing styles in a loop, forcing synchronous layout on every iteration
  • Heavy paint — large box-shadows, CSS filters, or full-page gradients that must be re-rasterized
  • Non-composited animations running during resize — competing for the main thread

Mitigations:

  • Batch read/write operations; use requestAnimationFrame for visual updates
  • Reduce layout dependencies (avoid percentage-based chains where possible)
  • Prefer compositor-friendly animations (transform, opacity) that do not trigger layout/paint
  • Debounce expensive resize handlers
  • Use CSS contain: layout on independent regions to limit reflow scope

Q17. Design a minimal accessible form for "reset password."

Why interviewers ask: Tests practical accessibility knowledge — labels, validation, error handling, security awareness.

Model answer:

<form method="post" action="/auth/reset">
  <h1>Reset your password</h1>

  <label for="email">Email address</label>
  <input
    id="email"
    name="email"
    type="email"
    autocomplete="email"
    required
    aria-describedby="email-error"
  />
  <p id="email-error" role="alert" aria-live="assertive"></p>

  <button type="submit">Send reset link</button>
</form>

Key decisions:

ConcernImplementation
Accessible name<label for="email"> — click target + screen reader name
Error feedbackaria-live="assertive" region announces errors without navigation
Autocompleteautocomplete="email" — helps password managers
Server validationCSRF token (framework-provided), rate limiting, avoid user enumeration
KeyboardNative <input> + <button> — full keyboard support out of the box

Security note: Whether the response reveals "email not found" vs a generic "if an account exists, we sent a link" is a product/security decision around user enumeration.


Q18. How would you eliminate CLS on a page with a hero image, web fonts, and a cookie consent banner?

Why interviewers ask: Tests holistic performance thinking — multiple CLS sources interacting.

Model answer:

CLS sourceFix
Hero imageAdd width and height attributes (or CSS aspect-ratio); use fetchpriority="high" for LCP; do not lazy-load it
Web fontsUse font-display: swap or optional; preload critical font files (<link rel="preload" as="font" crossorigin>); consider fallback font metrics matching (size-adjust)
Cookie bannerRender in a fixed/sticky position (overlay, not inserted above content); or reserve space at the top; load the banner script early so it renders before first interaction

General principles:

  • Reserve space for everything that might load late
  • Avoid inserting content above existing UI after initial render
  • Measure with Lighthouse and Chrome's Layout Shift Regions overlay

Q19. A colleague wraps every component in <article> "for SEO." Is this correct?

Why interviewers ask: Tests whether you can push back on cargo-cult practices with reasoned arguments.

Model answer:

No. <article> means self-contained composition — content that makes sense independently and could be syndicated (a blog post, a comment, a product card). Wrapping a header logo, a nav bar, or a footer social icons section in <article> is semantically incorrect.

Consequences of overuse:

  • Accessibility pollution — screen readers list articles in their rotor; dozens of false articles create noise
  • SEO: search engines use semantic signals to understand page structure; incorrect signals can confuse rather than help
  • Maintainability — future developers inherit misleading structure

Correct approach: Use <article> only when the content is genuinely self-contained. Use <section> for thematic groupings with headings. Use <div> for styling-only containers. Meaning over superstition.


Q20. Explain the accessibility tree and how it relates to the DOM.

Why interviewers ask: Advanced question that shows deep understanding of how assistive tech actually works.

Model answer:

The accessibility tree is a parallel representation of the DOM that the browser builds for assistive technologies. While the DOM describes document structure and the render tree describes visual layout, the accessibility tree describes semantic meaning:

PropertySource
RoleElement type (<button> → "button") or role attribute
Name<label>, aria-label, aria-labelledby, text content, alt
Statearia-expanded, aria-checked, disabled, required
ValueInput values, selected options
Relationshipsaria-describedby, aria-owns, parent/child structure

Key insight: When you use <div onclick> instead of <button>, the DOM node exists but the accessibility tree has no role, no name, no keyboard behavior. Semantic HTML fills the accessibility tree automatically; ARIA patches it manually when native HTML cannot express what you need.

DevTools: Chrome's Accessibility panel shows the computed accessibility tree — compare it to your DOM to spot gaps.


Quick-Fire (Yes / No + one line)

QuestionAnswerOne-line rationale
Is CSS render-blocking?YesBrowser won't paint until CSSOM is built — late CSS delays first paint.
Does display: none appear in the render tree?NoExcluded from the render tree entirely — not painted, not laid out.
Can transform changes skip layout and paint?YesCompositor-only changes when the element is on its own layer.
Is <section> a landmark by default?DependsOnly when it has an accessible name (via aria-label or aria-labelledby).
Should every page have exactly one <h1>?Generally yesStandard rule for multi-page sites; SPAs may adapt per view.
Does aria-label override visible text for AT?YesCan diverge from what sighted users see — use carefully.
Is placeholder a substitute for <label>?NoPlaceholders disappear on input and have low contrast — labels are required.
Can srcset serve different image formats?Nosrcset handles resolution; use <picture> for format negotiation.
Does loading="lazy" help the LCP image?NoIt delays loading — never lazy-load the Largest Contentful Paint element.
Is client-side validation sufficient for security?NoUsers can bypass it — server-side validation is the source of truth.

Interview Tips

  1. Start high-level, then drill down. "The browser parses HTML into the DOM, CSS into the CSSOM, combines them…" — then offer to go deeper on any stage.
  2. Draw the pipeline. Even verbally: "Imagine DOM on the left, pixels on the right, with layout and paint in between."
  3. Connect semantics to real users. "A screen reader user opens the landmarks rotor and sees…" is more convincing than abstract definitions.
  4. Name the trade-offs. "AVIF is smaller but slower to encode" or "ARIA is powerful but fragile if native HTML already works."
  5. Mention accessibility proactively. Interviewers notice candidates who think about inclusive design without being prompted.
  6. Know CLS / LCP / FCP. Core Web Vitals come up in every performance question — have one example fix for each.
  7. Security reflex. For any form or validation question, mention that the server is the trust boundary — "Never trust the client."
  8. Be honest about what you would test. "I would check with a screen reader and Lighthouse" shows practical experience over theory.

Use this alongside the 1.5 Exercise Questions for hands-on practice and deeper review.