β Part 1: Top 30 HTML Interview Questions and Answers (Easy to Advanced)

Table of contents
- π’ 1. What is HTML?
- π’ 2. What is the difference between HTML and HTML5?
- π’ 3. What are semantic tags?
- π’ 4. What does <!DOCTYPE html> do?
- π’ 5. What is the difference between <div> and <span>?
- π’ 6. What is an HTML attribute?
- π’ 7. What are void (empty) elements?
- π’ 8. What is the difference between id and class?
- π’ 9. What is the use of <meta> tag?
- π’ 10. What is the purpose of the <head> and <body> tags?
- π’ 11. What is the difference between <ul>, <ol>, and <dl>?
- π’ 12. What is the use of <iframe> in HTML?
- π’ 13. What are block and inline elements?
- π’ 14. What is the use of the <form> tag?
- π’ 15. Name some common input types in HTML5.
- π’ 16. What is the difference between name and id in form elements?
- π’ 17. What is the use of the placeholder attribute?
- π’ 18. What is the purpose of the required attribute?
- π’ 19. What is the difference between submit and button types?
- π’ 20. How can we create a hyperlink in HTML?
- π’ 21. How do you insert an image in HTML?
- π’ 22. What is the alt attribute in <img>?
- π’ 23. What are HTML entities?
- π’ 24. What is the purpose of the <br> and <hr> tags?
- π’ 25. What is the target attribute in links?
- π’ 26. What is the use of <label> in forms?
- π’ 27. What is nesting in HTML?
- π’ 28. Can we write HTML without the <html>, <head>, or <body> tags?
- π’ 29. What is the use of the <title> tag?
- π’ 30. How does the browser render HTML?
Introduction:
If you're preparing for a frontend developer interview, this article is for you. Here are 30 important HTML interview questions with simple and clear answers. These questions cover basic to advanced levels and are helpful for both freshers and experienced candidates. Every answer is written in easy English so that you can confidently explain the concepts in interviews.
π’ 1. What is HTML?
Answer:
HTML stands for HyperText Markup Language. It is used to create the structure of web pages. It tells the browser what to display β like headings, paragraphs, links, images, etc.
Example:
<h1>Hello World</h1>
π’ 2. What is the difference between HTML and HTML5?
Answer:
HTML is the older version. HTML5 is the latest version and supports new features like:
<audio>
and<video>
tagsNew input types like
email
,date
,range
Semantic tags like
<header>
,<footer>
,<section>
Better performance and mobile support
π’ 3. What are semantic tags?
Answer:
Semantic tags clearly define the meaning of content. They make the HTML more readable and better for SEO.
Examples:
<article>
β for blog posts<nav>
β for navigation<footer>
β for page footer
π’ 4. What does <!DOCTYPE html>
do?
Answer:
It tells the browser to use the latest HTML5 standard to render the page. It should always be the first line in an HTML document.
π’ 5. What is the difference between <div>
and <span>
?
Answer:
<div>
is a block-level element (takes full width).<span>
is an inline element (fits within a line).
Use<div>
for layout and<span>
for styling small text.
π’ 6. What is an HTML attribute?
Answer:
An attribute gives extra information about an element. It is written inside the opening tag.
Example:
<a href="https://example.com">Visit</a>
Here, href
is an attribute.
π’ 7. What are void (empty) elements?
Answer:
Void elements are those that do not have a closing tag.
Examples: <br>
, <img>
, <input>
, <hr>
π’ 8. What is the difference between id
and class
?
Answer:
id
is unique and used for one element.class
can be used for multiple elements.
Both are used for styling or JavaScript targeting.
π’ 9. What is the use of <meta>
tag?
Answer:
The <meta>
tag provides metadata like description, keywords, charset, and viewport settings.
Example:
<meta name="description" content="HTML Interview Questions">
π’ 10. What is the purpose of the <head>
and <body>
tags?
Answer:
<head>
contains metadata, links to stylesheets, and scripts.<body>
contains the visible content of the page.
π’ 11. What is the difference between <ul>
, <ol>
, and <dl>
?
Answer:
<ul>
β Unordered list (bullets)<ol>
β Ordered list (numbers)<dl>
β Definition list (terms and descriptions)
π’ 12. What is the use of <iframe>
in HTML?
Answer:
An <iframe>
is used to embed another webpage inside the current page.
Example:
<iframe src="https://example.com"></iframe>
π’ 13. What are block and inline elements?
Answer:
Block elements: take full width (e.g.,
<div>
,<p>
)Inline elements: fit inside a line (e.g.,
<a>
,<span>
)
π’ 14. What is the use of the <form>
tag?
Answer:
The <form>
tag is used to collect user input like name, email, etc. It usually has input fields, buttons, and a submit action.
π’ 15. Name some common input types in HTML5.
Answer:
text
email
password
number
date
range
color
π’ 16. What is the difference between name
and id
in form elements?
Answer:
id
: used for JavaScript and CSS targetingname
: used to send form data to the server
π’ 17. What is the use of the placeholder
attribute?
Answer:
It shows a temporary hint inside an input field.
Example:
<input type="text" placeholder="Enter your name">
π’ 18. What is the purpose of the required
attribute?
Answer:
It makes a form field mandatory. The user cannot submit the form without filling it.
π’ 19. What is the difference between submit
and button
types?
Answer:
type="submit"
: submits the formtype="button"
: does not submit the form (used with JavaScript)
π’ 20. How can we create a hyperlink in HTML?
Answer:
Use the <a>
tag with the href
attribute.
Example:
<a href="https://google.com">Visit Google</a>
π’ 21. How do you insert an image in HTML?
Answer:
Use the <img>
tag with src
and alt
attributes.
Example:
<img src="image.jpg" alt="My Image">
π’ 22. What is the alt
attribute in <img>
?
Answer:
It shows alternative text when the image can't load. It also improves accessibility and SEO.
π’ 23. What are HTML entities?
Answer:
They are used to display reserved characters like <
, >
, &
, etc.
Example:<
for <
, >
for >
, &
for &
π’ 24. What is the purpose of the <br>
and <hr>
tags?
Answer:
<br>
adds a line break<hr>
adds a horizontal line (used to separate content)
π’ 25. What is the target
attribute in links?
Answer:
It controls where the link opens.
Example:
<a href="https://google.com" target="_blank">Google</a>
This opens the link in a new tab.
π’ 26. What is the use of <label>
in forms?
Answer:
It gives a name to input fields and improves accessibility.
Example:
<label for="email">Email:</label>
<input id="email" type="email">
π’ 27. What is nesting in HTML?
Answer:
It means placing tags inside other tags in a proper structure.
Example:
<p>This is a <strong>bold</strong> word.</p>
π’ 28. Can we write HTML without the <html>
, <head>
, or <body>
tags?
Answer:
It might still work in some browsers, but it's not correct. Always include them for proper structure.
π’ 29. What is the use of the <title>
tag?
Answer:
It defines the title shown in the browser tab. It also helps with SEO.
π’ 30. How does the browser render HTML?
Answer:
The browser reads HTML from top to bottom and displays the content step-by-step. It follows the structure and tags to build the web page layout.
π Conclusion
These 30 HTML interview questions cover the most commonly asked concepts in frontend development interviews. Practice them well, and try to explain the answers in your own words too. Stay tuned for Part 2, where weβll cover more HTML interview questions and answers.
Subscribe to my newsletter
Read articles from Payal Porwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Porwal
Payal Porwal
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: π In-depth explorations of emerging technologies π‘ Practical tutorials and how-to guides π§Insights on software development best practices πReviews of the latest tools and frameworks π‘ Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Letβs connect and grow together! π