Back to Interview PrepGet interview ready with AILearn each topic the way interviewers ask it, then answer like you would in the interview.

Chapter 14 of 14

Top 114 HTML Interview Questions

A rapid-fire reference covering the questions most likely to come up in a real interview - organized by topic and difficulty, with explanations that go beyond a one-line definition and a runnable code example for each one, so the concept sticks. Search or filter to find what you need, and share a direct link to any question.

Level:

Showing 114 of 114 questions

Questions reviewed0/114 · 0%

The first 15 of 114 questions are free to read. Sign up free to unlock every answer and track your progress.

Unlock all 114

HTML (HyperText Markup Language) defines the structure and meaning of content on a web page - headings, paragraphs, lists, links, and so on. It doesn’t control appearance or behavior; CSS handles presentation and JavaScript handles interactivity. Together they form the three layers browsers combine to render a working page.

Example

<!-- HTML: structure -->
<button id="btn">Click me</button>

<!-- CSS: presentation -->
<style>#btn { color: blue; }</style>

<!-- JS: behavior -->
<script>btn.onclick = () => alert('Hi!');</script>

<!DOCTYPE html> tells the browser to render the page in standards mode rather than quirks mode, which mimics old, inconsistent browser behavior from the 1990s. Without it, browsers may apply different box-model and layout rules, causing subtle rendering bugs. It isn’t an HTML tag itself - it’s an instruction to the parser.

Example

<!DOCTYPE html>
<html>
  <head><title>Standards Mode</title></head>
  <body>Hello</body>
</html>

A tag is the markup syntax itself, like <p> or </p>, while an element is the full unit - opening tag, content, and closing tag - that the tag represents. People often use the words interchangeably in casual conversation, but technically the tag is just the label and the element is the whole structure the browser builds from it.

Example

<p>Hello</p>
<!-- <p> and </p> are tags; the whole <p>Hello</p> is the element -->

The DOM (Document Object Model) is the tree-like, in-memory representation the browser builds after parsing HTML. It’s what CSS selectors match against and what JavaScript reads and mutates at runtime - so the DOM can diverge from the original HTML source once scripts start modifying it. Viewing “page source” shows the original HTML; inspecting elements in devtools shows the live DOM.

Example

<ul id="list">
  <li>Item</li>
</ul>
<!-- Browser builds: Document > ul#list > li -->

Void elements never wrap content and have no closing tag because there’s nothing to close - examples include <br>, <img>, <hr>, <input>, <meta>, and <link>. In HTML5 the trailing slash (<br />) is optional and purely stylistic, unlike in strict XHTML where it was required.

Example

<img src="cat.jpg" alt="A cat">
<br>
<hr>
<input type="text">

No - tag names and attribute names in HTML5 are case-insensitive, so <DIV> and <div> behave identically. That said, lowercase is the universal convention because it’s more readable and matches how XHTML and most style guides expect markup to look. Attribute values, however, can be case-sensitive depending on what they represent, like a file path.

Example

<DIV>Same as</DIV>
<div>this div</div>

HTML comments are written as <!-- comment text -->, and the browser ignores everything between those markers when rendering. They’re not visible in the rendered page, but anyone can still see them by viewing the page source, so they should never contain sensitive information like internal notes or credentials.

Example

<!-- This won't be visible on the page -->
<p>Visible text</p>

A valid document starts with <!DOCTYPE html>, then an <html> root element containing a <head> for metadata (title, charset, links to stylesheets) and a <body> for the visible content. Browsers are forgiving and will often render pages missing pieces of this structure, but omitting them risks inconsistent rendering and accessibility issues.

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>My Page</title>
  </head>
  <body>
    <p>Content goes here</p>
  </body>
</html>

Browsers ignore unknown tags entirely for rendering purposes but still add them to the DOM as generic inline elements, and they’ll still render any text content inside. This forgiving behavior is why custom elements and web components work - the browser doesn’t reject unfamiliar markup, it just treats it plainly until JavaScript upgrades it.

Example

<foo-bar>Still rendered as text</foo-bar>
<!-- Browser adds an unknown HTMLElement to the DOM -->

HTML5 is the current major version of the HTML specification, introducing semantic elements (header, nav, article, section), native form validation, multimedia tags like <video> and <audio>, canvas, and APIs like local storage and geolocation. Earlier versions relied heavily on generic <div> soup and plugins like Flash for anything HTML couldn’t natively do.

Example

<!-- HTML5 semantic elements -->
<header>Site Header</header>
<nav>Navigation</nav>
<article>Post content</article>

Global attributes are attributes that can be applied to virtually any HTML element, such as id, class, style, title, lang, tabindex, and data-* attributes. They exist because certain behaviors - identification, styling hooks, accessibility, custom data - are useful regardless of what element you’re working with.

Example

<p id="intro" class="lead" title="Tooltip" data-user-id="42">Hello</p>

data-* attributes let you embed custom data directly on an element without inventing non-standard attributes that would fail validation, such as data-user-id="42". JavaScript can read them conveniently through the element’s dataset property, and they’re commonly used to pass server-rendered values to client-side scripts or CSS selectors.

Example

<li data-user-id="42">Jane</li>
<script>
  console.log(document.querySelector('li').dataset.userId); // "42"
</script>

Setting contenteditable="true" on an element makes its content directly editable by the user in the browser, similar to a rich text editor. It’s the foundation many WYSIWYG editors are built on, though it comes with quirks around pasting, cursor handling, and inconsistent behavior across browsers that usually require extra JavaScript to smooth over.

Example

<div contenteditable="true">Click and start typing here...</div>

Block-level elements, like <div>, <p>, and <section>, start on a new line and take up the full available width by default. Inline elements, like <span>, <a>, and <strong>, flow within the surrounding text and only take up as much width as their content needs. This default behavior can be overridden with CSS display, but the distinction still shapes how browsers treat nesting rules.

Example

<div>Block: full width, new line</div>
<span>Inline: flows with text</span>

An id must be unique within the page and is meant to identify a single specific element - useful for anchor links, form label association, and JavaScript targeting. A class can be applied to many elements and is meant for grouping elements that share styling or behavior. Using duplicate ids is invalid HTML and can cause unpredictable behavior with APIs like getElementById.

Example

<div id="header" class="box highlighted">...</div>
<div class="box">...</div>
16.Do attribute values always need to be quoted?17.What are boolean attributes, and how do they differ from regular attributes?18.Can you create custom, non-standard HTML attributes?19.What is the title attribute used for, and how does it differ from the <title> tag?20.Why might you use a <span> instead of a <div>, or vice versa?21.What is semantic HTML, and why does it matter?22.What’s the difference between <section>, <article>, and <div>?23.What are ARIA attributes, and when should you use them?24.Why is the alt attribute on images important?25.What are landmark roles, and how do semantic tags relate to them?26.What makes a form accessible?27.What is the tabindex attribute, and what do its different values mean?28.What is a “skip link,” and why is it important?29.Why does heading hierarchy (h1–h6) matter beyond visual size?30.What’s the difference between aria-hidden and the hidden attribute?31.What’s the difference between GET and POST form submission?32.How does the label element improve forms, and how do you associate it with an input?33.What are some of the more useful HTML5 input types beyond text?34.How does native HTML5 form validation work?35.What do <fieldset> and <legend> do?36.What does the autocomplete attribute do?37.What happens by default when a form is submitted?38.What is FormData, and why is it useful?39.Why does every form control need a name attribute?40.What’s the difference between disabled and readonly on an input?41.What are the core building blocks of an HTML table?42.Why use <thead>, <tbody>, and <tfoot> instead of just a flat list of <tr> elements?43.What do colspan and rowspan do?44.When is it appropriate to use a table, and when is it not?45.What’s the difference between <ul>, <ol>, and <dl>?46.Can you nest lists inside each other, and how is that structured?47.What is the scope attribute used for on table headers?48.How would you add a caption to a table, and why use it instead of a preceding paragraph?49.How do you make a large HTML table responsive on small screens?50.Are <ul> and <ol> block-level or inline elements, and how does that affect their <li> children?51.What’s the difference between a relative and an absolute URL?52.What does the target="_blank" attribute do, and why should it usually be paired with rel="noopener"?53.What is the srcset attribute on <img>, and what problem does it solve?54.What does loading="lazy" do on an image, and when should you avoid it?55.What is the <picture> element used for, and how does it differ from srcset alone?56.What are the key attributes to know for the <video> and <audio> elements?57.What security considerations apply to <iframe>, and what does the sandbox attribute do?58.What does the rel attribute on a link tag or anchor communicate?59.Besides the src and alt attributes, what other image attributes matter for performance?60.How does an anchor link to a specific section within the same page?61.What kinds of content typically live inside <head>?62.Why is <meta charset="UTF-8"> important, and where should it be placed?63.What does the viewport meta tag do, and why is it essential for mobile?64.How does the meta description tag affect SEO?65.What are Open Graph tags, and what are they used for?66.Why does the <title> tag matter so much for SEO and usability?67.How do you add a favicon to a page, and does it require more than one file?68.What does a canonical link tag do, and why is it useful?69.What does the robots meta tag control?70.Can a page have multiple <meta> tags with the same name, and does order matter?71.What were the major additions introduced in HTML5?72.What’s the difference between <canvas> and SVG?73.What’s the difference between localStorage and sessionStorage?74.How does the Geolocation API work at a basic level?75.How does native drag and drop work in HTML5?76.What are web workers, conceptually, and why do they matter?77.What does the History API allow you to do?78.What is the <template> element used for?79.What are Web Storage’s main limitations compared to something like IndexedDB?80.What is the difference between a normal element and a custom element from the Web Components spec?81.What does it mean for a script to be render-blocking, and how do async and defer help?82.Why are inline styles generally discouraged?83.What does HTML validation mean, and why bother validating markup?84.What image optimization practices most directly affect page performance?85.Why should the doctype and correct nesting matter for performance, not just correctness?86.What are some HTML tags considered deprecated or obsolete, and why avoid them?87.How does the order of resources in <head> affect perceived page load speed?88.What is Cumulative Layout Shift, and what HTML practices help prevent it?89.Why is minimizing the number of DOM nodes considered a best practice?90.What role does semantic HTML play in performance, beyond accessibility?91.What’s the actual difference between <b> and <strong>, or <i> and <em>?92.When should you use <div> versus <span>, and what’s the risk of overusing them?93.Do void elements need to be self-closed in HTML5?94.What issues can arise from incorrect character encoding in HTML?95.What was XHTML, and how does it differ from HTML5?96.What are custom elements, and what’s required to define one?97.What is the Shadow DOM, conceptually, and why is it useful for components?98.Why can the rendered DOM differ from the original HTML source at runtime?99.Why can’t you nest a <p> tag inside another <p> tag, and what actually happens if you try?100.What’s the practical difference between styling something with HTML attributes versus relying entirely on CSS?101.What does the native <dialog> element give you, and how do you open it as a modal?102.What do <details> and <summary> do, and why use them over a JavaScript accordion?103.What is the <datalist> element, and how does it differ from a <select> dropdown?104.What is the <output> element for?105.What’s the difference between <progress> and <meter>?106.What do you need to configure on a form to support file uploads, and why?107.What does the autofocus attribute do, and what’s a downside of overusing it?108.What is Subresource Integrity, and how do integrity and crossorigin work together on a <script> or <link> tag?109.How does <script type="module"> differ from a classic script?110.What does the <track> element do for video, and what is the poster attribute for?111.What’s the difference between preconnect, dns-prefetch, prefetch, and preload, and when would you use each?112.Can Content-Security-Policy be set via a <meta> tag, and how does that compare to setting it as an HTTP header?113.What do the <base> element and <noscript> do?114.What is a Web App Manifest, and what does linking one enable?
You're viewing a free lesson. Sign up free to track your progress and unlock the full course.Sign up freeSign in