Most Asked HTML Interview Question And Answer
HTML Interview Questions and Answers
If you are preparing for an HTML viva, exam, or interview, this guide will help you. I’ve explained basic and advanced HTML questions in a simple way with examples. Let’s start.
✅ Basic HTML Questions and Answers
1. What is HTML and what is its purpose in web development?
HTML stands for HyperText Markup Language. It is the skeleton of a webpage. Just like our body has bones for structure, websites have HTML for structure.
-
Example: Headings, paragraphs, images, links, and forms are created using HTML.
2. What is the difference between an element, a tag, and an attribute in HTML?
-
Tag: The code inside
< >
. Example:<p>
. -
Element: The complete thing with opening and closing tag plus content. Example:
<p>Hello</p>
. -
Attribute: Extra information given inside a tag. Example:
<img src="car.jpg" alt="Car">
-
src
andalt
are attributes.
-
3. What are semantic elements in HTML, and is div a semantic element?
Semantic elements are tags that clearly explain their purpose.
-
Example:
-
<header>
→ for top section -
<nav>
→ for navigation links -
<footer>
→ for bottom section
-
<div>
is not semantic. It’s just a container with no meaning by itself.
4. What is the difference between block-level and inline elements?
-
Block elements: Start on a new line and take full width. Example:
<div>
,<p>
,<h1>
. -
Inline elements: Stay in the same line and take only the required space. Example:
<span>
,<a>
,<img>
.
5. What is the difference between the strong, bold, em, and i tags?
-
<strong>
→ Makes text bold and gives importance (semantic). -
<b>
→ Only makes text bold (no meaning). -
<em>
→ Emphasizes text (semantic, read with stress). -
<i>
→ Only makes text italic (no meaning).
👉 Semantic tags (<strong>
, <em>
) are preferred in modern HTML.
✅ Advanced HTML Questions
6. What is the difference between absolute and relative URLs?
-
Absolute URL → Full web address (works from anywhere). Example:
<a href="https://example.com/about.html">About Us</a>
-
Relative URL → Short path relative to current file. Example:
<a href="about.html">About Us</a>
7. What is the difference between the id and class attributes?
-
id → Unique, used once. Example:
<div id="header"></div>
-
class → Can be reused. Example:
<div class="box"></div>
In CSS:
-
#header {}
→ for id -
.box {}
→ for class
8. What is the difference between session storage and local storage?
Both are used to store data in the browser.
-
Session storage: Data is available only until the browser tab is open.
-
Local storage: Data remains even after closing the browser.
9. How do you add CSS styling in HTML?
There are 3 ways:
-
Inline CSS → inside tag
<p style="color: red;">Hello</p>
-
Internal CSS → inside
<style>
<style> p { color: red; } </style>
-
External CSS → separate file linked with
<link>
.
10. How do you create a hyperlink in HTML?
<a href="https://example.com">Click Here</a>
This will take the user to another webpage.
11. What is the difference between cell spacing and cell padding?
-
Cell spacing → Space between two table cells.
-
Cell padding → Space inside a cell (between text and border).
12. How do you create a table in HTML with a table name and column headers?
<table border="1">
<caption>Student Marks</caption>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Harsh</td>
<td>90</td>
</tr>
</table>
13. How do you create a checkbox in HTML?
<input type="checkbox" name="subject" value="HTML"> HTML
14. How do you create a dropdown list in HTML?
<select name="course">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
</select>
15. What are forms and how do you create them in HTML?
Forms are used to collect user input like name, email, password.
Example:
<form action="/submit" method="post">
<label>Name: <input type="text" name="username"></label><br>
<label>Email: <input type="email" name="email"></label><br>
<button type="submit">Submit</button>
</form>
🎯 Final Words
These are the most commonly asked HTML questions in interviews and exams. If you understand these concepts, you’ll easily answer viva questions and build real web pages confidently.