HTML & HTML5 Interview Questions & Answers
Welcome to our comprehensive HTML interview preparation guide. HTML (HyperText Markup Language) is the backbone of the web. Regardless of whether you specialize in frontend frameworks like React or backend languages like Java and Python, having deep command over HTML5 semantic tags, DOM manipulation, accessibility (a11y), and web storage is critical for passing technical rounds.
What is HTML, and how does it relate to the DOM?
HTML (HyperText Markup Language) is the standard markup language used to structure web pages and their content. However, in an interview, it's crucial to explain its relationship to the DOM.
When a browser reads an HTML document, it creates a Document Object Model (DOM). The DOM is an object-oriented representation of the HTML document that acts as an interface between JavaScript and the document itself.
<html>
<body>
<h1 id="heading">Hello World</h1>
</body>
</html>
// And creates a DOM tree where JavaScript can manipulate it:
document.getElementById('heading').textContent = "Updated Text";
What is the difference between HTML and HTML5? Can you name some new features?
HTML5 is the latest major revision of HTML. It introduced native support for multimedia, semantic structuring, and advanced APIs, moving away from relying on third-party plugins like Flash.
Key differences and new features include:
- Semantic Tags: Introduced tags like
<header>,<footer>,<article>, and<nav>which provide meaning to web crawlers and screen readers. - Multimedia: Native
<audio>and<video>tags. - Graphics: Added
<canvas>and native SVG support for 2D/3D graphics. - Storage APIs: Introduced Local Storage and Session Storage to replace cumbersome cookies.
- Form Enhancements: New input types like
date,email,range, and built-in validation attributes likerequired.
What are Semantic HTML tags and why are they critical?
Semantic tags are HTML elements that clearly describe their meaning to both the browser and the developer (e.g., <form>, <table>, <article>) as opposed to non-semantic tags which tell nothing about their content (e.g., <div>, <span>).
Why are they critical?
- Accessibility (A11y): Screen readers rely on semantic tags to navigate a page. A blind user can jump from
<nav>to<main>easily, but cannot do so if everything is a<div>. - SEO (Search Engine Optimization): Search engines give higher priority to content inside
<h1>or<article>than generic text in a<span>. - Maintainability: It's much easier for developers to read and understand code structured with meaningful tags.
What is the difference between normal <script>, <script async>, and <script defer>?
This is a critical web performance and rendering question:
- Normal <script>: HTML parsing pauses immediately while the script is fetched and executed, blocking page rendering until complete.
- <script async>: The script is fetched asynchronously in parallel with HTML parsing. As soon as it downloads, HTML parsing pauses to execute the script immediately. Order of execution is not guaranteed.
- <script defer>: The script is fetched asynchronously in parallel with HTML parsing, but its execution is deferred until HTML parsing completes (before
DOMContentLoaded). Scripts execute in the exact order they appear in the document.
What is the purpose of the <head> tag?
What are void elements in HTML?
What is the difference between id and class in HTML?
What does the <doctype> declaration do?
What is the difference between block and inline elements?
What is the use of the <meta> tag?
How do you create a hyperlink in HTML?
What are formatting tags in HTML?
What is the purpose of <div> and <span>?
What is the difference between relative and absolute URLs?
What are HTML attributes?
What is the <iframe> tag used for?
What is a list in HTML?
What is the use of the <label> tag?
How do you create a table in HTML?
What is the difference between <strong> and <b>?
What is the role of the <script> tag?
What are self-closing tags?
What is the difference between <em> and <i>?
What is nesting in HTML?
What are global attributes in HTML?
What is accessibility in HTML?
What is the <canvas> tag used for?
How can you comment in HTML?
What is the use of <fieldset> and <legend>?
What is the difference between <section> and <div>?
What is the purpose of the <style> tag in HTML?
How is the <link> tag used in HTML?
What are the differences between <head> and <body> tags?
What is the role of <title> tag in HTML?
What are empty elements in HTML?
What are examples of non-semantic tags?
What are types of syntactic elements in HTML?
Is there a difference between formatting tags and semantic formatting tags?
Why is using semantic formatting preferred over purely visual formatting?
Need 1-on-1 Mock Interview & Career Mentorship in Telugu?
Practice live coding interviews with senior industry architects. We simulate real enterprise screening rounds for HTML, CSS, JavaScript, React, Node.js, and Java full-stack roles.