REVIEWED STARTER COLLECTIONHTML Interview Questions
Short answer se start karo, phir interview-level explanation, small HTML example aur common follow-up revise karo. Ye collection canonical HTML tutorial ko duplicate ya replace nahi karta.
1. What is semantic HTML and why is it important?
Short AnswerSemantic HTML uses elements whose names describe their purpose, such as <main>, <nav>, <article> and <footer>.
Detailed ExplanationSemantic elements make document structure easier for developers, browsers and assistive technologies to understand. They can improve accessibility and maintainability, and they give search engines clearer structural signals.
<main>
<article>
<h1>CSS Basics</h1>
<p>Learn the fundamentals.</p>
</article>
</main>
Common follow-up: Semantic HTML does not automatically make a page accessible; correct headings, labels, alt text, keyboard behavior and other details still matter.
Learn this concept →
2. What does <!doctype html> do?
Short AnswerIt tells the browser to render the document using modern HTML standards mode.
Detailed ExplanationThe doctype is a declaration placed before the <html> element. In modern HTML it is intentionally simple. Omitting it can cause browsers to enter quirks mode, where some legacy layout behavior is used.
<!doctype html>
<html lang="en">
<head>...</head>
<body>...</body>
</html>
Common follow-up: The doctype is not an HTML element and does not need a closing tag.
Learn this concept →
3. What is the difference between id, name and label for in a form?
Short Answerid uniquely identifies an element in the document, name identifies the submitted form field, and a label's for value connects the label to the matching input id.
Detailed ExplanationThe id is useful for DOM references, fragment links and label association. The name becomes the key used when successful form controls are submitted. Proper label association improves usability and accessibility.
<label for="email">Email</label>
<input id="email" name="email" type="email">
Common follow-up: An input can have an id and still be missing from normal form submission if it has no name.
Learn this concept →
4. What is the purpose of the alt attribute on an image?
Short Answeralt provides a text alternative that communicates the image's purpose or content when the image cannot be perceived visually.
Detailed ExplanationUseful alt text depends on context. Informative images need concise meaningful text, while purely decorative images commonly use alt="" so assistive technology can ignore them.
<img
src="sales-chart.png"
alt="Quarterly sales increased from Q1 to Q4"
>
Common follow-up: Do not start every alt value with “image of.” Screen readers already expose the element as an image.
Learn this concept →
5. Why should you use a native <button> instead of a clickable <div> for actions?
Short AnswerA native <button> already has button semantics and built-in keyboard interaction, while a plain <div> does not.
Detailed ExplanationUsing the correct native element reduces custom accessibility work. A clickable div typically needs extra keyboard handling, focus behavior and semantic roles just to imitate what a button already provides.
<button type="button">Open menu</button>
<!-- Avoid using a plain div as a button -->
<div onclick="openMenu()">Open menu</div>
Common follow-up: Use links for navigation to another URL and buttons for actions that happen on the current interface.
Learn semantics →Learn form controls →