HTML Interview Questions & Answers
1. What is HTML?
Answer: HTML is a language used to create web pages. It helps you structure content using tags
like headings, paragraphs, images, and links.
2. Difference between HTML and XHTML?
Answer: XHTML is stricter than HTML. In XHTML, all tags must be closed, lowercase, and properly
nested. HTML is more flexible.
3. What are semantic tags?
Answer: Semantic tags clearly describe their meaning to both browser and developer. Examples:
<header>, <footer>, <article>, <nav>.
4. Difference between <div> and <span>?
Answer: <div> is a block element used for large sections; <span> is inline used for small text or
styling within a line.
5. Purpose of <head> and <body>?
Answer: <head> contains meta info, title, and links. <body> contains the content visible to the user.
6. What is the <meta> tag used for?
Answer: Provides information like page charset, description, and viewport for mobile
responsiveness.
7. Difference between <section> and <article>?
Answer: <section> groups related content. <article> is for self-contained content like a blog post.
8. Difference between <ul>, <ol>, and <dl>?
Answer: <ul> = unordered list, <ol> = ordered list, <dl> = description list.
9. What is a <form> and its attributes?
Answer: A form collects user input. Attributes include action (where to send data), method (GET or
POST), and enctype (for file uploads).
10. Difference between GET and POST?
Answer: GET sends data in the URL, visible to users. POST sends data in the request body, more
secure and hidden.
11. HTML5 input types?
Answer: Examples include text, number, email, password, date, color, url.
12. Purpose of alt in <img>?
Answer: Provides alternative text if an image fails to load. Helps screen readers for accessibility.
13. Difference between <iframe> and <embed>?
Answer: <iframe embeds another HTML page. <embed embeds media like video, audio, or PDF
files.
14. Difference between <strong> and <b>?
Answer: <strong> indicates importance (semantic). <b> is just visual bold text.
15. Difference between <em> and <i>?
Answer: <em> emphasizes text (semantic). <i> italicizes text visually.
16. What are HTML entities?
Answer: Special codes to display reserved characters, like < for <, > for >, for space.
17. Inline, block, inline-block difference?
Answer: Inline stays in line, block starts on a new line, inline-block stays in line but can have width
and height.
18. What is <canvas> used for?
Answer: Used to draw graphics, charts, or animations with JavaScript.
19. How to include JavaScript in HTML?
Answer: Use <script> tag. Inline: <script>alert('Hi')</script>, External: <script src='[Link]'></script>.
20. What are data-* attributes?
Answer: Custom attributes to store extra info, e.g., <div data-id='123'></div>. Can be accessed in
JS.