HTML Interview Question & Answers
1. What is HTML?
HTML stands for HyperText Markup Language. It is the standard
markup language used to create web pages.
2. What is the latest version of HTML?
nA
The latest version of HTML is HTML5.
3. What are the differences between HTML5 and HTML4?
HTML5 has new semantic elements, supports multimedia content,
and has improved support for client-side scripting. It also allows for
cleaner and more efficient coding practices.
iQ
4. What are the new features of HTML5?
Some of the new features of HTML5 include new semantic
elements, multimedia support, new form controls, local storage,
es
and canvas element for graphics.
5. What is a DOCTYPE in HTML?
A DOCTYPE declaration is used to specify the version of HTML or
XHTML being used in a web page. It tells the browser which
D
version of the language to use when rendering the page.
Example:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<!-- content here -->
</body>
</html>
6. What is the difference between HTML and XHTML?
HTML is an SGML-based markup language, while XHTML is an
nA
XML-based markup language. XHTML is stricter than HTML and
requires all tags to be properly nested and closed.
7.What are the semantic elements in HTML5?
Some of the semantic elements in HTML5 include header, footer,
iQ
nav, section, article, aside, and main.
Example:
<header>
es
<h1>My Website</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
D
</ul>
</nav>
</header>
<section>
<article>
<h2>Article Title</h2>
<p>Article content goes here.</p>
</article>
<aside>
<h3>Related Articles</h3>
<ul>
<li><a href="#">Related Article 1</a></li>
<li><a href="#">Related Article 2</a></li>
<li><a href="#">Related Article 3</a></li>
</ul>
</aside>
</section>
<footer>
<p>© 2023 My Website</p>
nA
</footer>
iQ
8. What is the difference between a div and a span in HTML?
A div is a block-level element that is used to group and format
content, while a span is an inline-level element that is used to
apply styles to specific portions of text.
es
Example:
<div>
<h2>Section Title</h2>
D
<p>Section content goes here.</p>
</div>
<p>This is a <span style="color: red;">red</span> word.</p>
9. What is the difference between an id and a class in HTML?
An id is a unique identifier that is used to identify a specific
element on a web page, while a class is a non-unique identifier
that is used to group elements with similar properties.
Example:
<div id="header">
<h1>My Website</h1>
</div>
nA
<p class="lead">This is the lead paragraph.</p>
<p class="lead">This is another lead paragraph.</p>
iQ
10 .What is the difference between a relative and absolute URL in
HTML?
A relative URL is a URL that is relative to the current page, while
an absolute URL is a URL that includes the entire web address,
es
including the protocol, domain name, and path.
Example:
<!-- Relative URL -->
D
<a href="about.html">About</a>
<!-- Absolute URL -->
<a href="https://www.example.com/about.html">About</a>
11. What is the alt attribute in HTML?
The alt attribute is used to provide alternative text for an image in
case it cannot be displayed. It is also used by screen readers to
describe the content of an image to visually impaired users.
Example:
<img src="image.jpg" alt="A beautiful landscape">
12. What is the role attribute in HTML?
nA
The role attribute is used to describe the role of an element in a
web page. It is used to provide additional information to assistive
technologies, such as screen readers.
Example:
iQ
<nav role="navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
es
</ul>
</nav>
D
13. What is the difference between a GET and a POST method in
HTML?
The GET method is used to request data from a server, while the
POST method is used to submit data to a server. The data sent
using the GET method is visible in the URL, while the data sent
using the POST method is not.
Example:
<!-- GET form -->
<form action="process.php" method="GET">
<label for="name">Name:</label>
<input type="text" name="name" id="name">
<input type="submit" value="Submit">
</form>
<!-- POST form -->
<form action="process.php" method="POST">
<label for="name">Name:</label>
nA
<input type="text" name="name" id="name">
<input type="submit" value="Submit">
</form>
14.What is the target attribute in HTML?
iQ
The target attribute is used to specify where to open the linked
document when a user clicks on a link. It can be set to _self to
open the document in the same frame, _blank to open the
document in a new window, or a frame name to open the
es
document in a specific frame.
Example:
<a href="https://www.example.com" target="_blank">Visit
D
Example.com</a>
15. What is the difference between a block-level element and an
inline-level element in HTML?
A block-level element takes up the full width available and creates
a new line, while an inline-level element only takes up the
necessary width and does not create a new line.
Example:
<div>
<p>This is a block-level element.</p>
<p>This is another block-level element.</p>
</div>
nA
<p>This is an <span>inline-level element</span>.</p>
16. What is the difference between the em tag and the strong tag in
iQ
HTML?
The em tag is used to indicate emphasis, while the strong tag is
used to indicate importance. Both tags are used to give text more
weight and make it stand out, but the strong tag is used for
es
stronger emphasis.
Example:
<p>This sentence is <em>emphasized</em>.</p>
<p>This sentence is <strong>important</strong>.</p>
D
17.What is the difference between the ul tag and the ol tag in HTML?
The ul tag is used to create an unordered list, while the ol tag is
used to create an ordered list. An unordered list uses bullet points,
while an ordered list uses numbers
Example:
<!-- Unordered List -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<!-- Ordered List -->
<ol>
<li>Item 1</li>
nA
<li>Item 2</li>
<li>Item 3</li>
</ol>
iQ
18. What is the difference between the input type "text" and "password"
in HTML?
The input type "text" displays the input text as plain text, while the
input type "password" displays the input text as masked text (e.g.,
es
asterisks or dots). This is used to hide sensitive information, such
as passwords.
Example:
D
<label for="username">Username:</label>
<input type="text" name="username" id="username">
<label for="password">Password:</label>
<input type="password" name="password" id="password">
19. What is the difference between the HTML tags "<span>" and
"<div>"?
The "<span>" tag is an inline element used to group inline-level
elements and apply styles to them, while the "<div>" tag is a
block-level element used to group block-level elements and apply
styles to them.
Example:
<span style="color: red;">This is a span element.</span>
<div style="color: blue;">This is a div element.</div>
nA
20 .What is the difference between the HTML tags "<strong>" and
iQ
"<em>"?
The "<strong>" tag is used to indicate strong importance, while the
"<em>" tag is used to indicate emphasis.
es
Example:
<strong>This is important text.</strong>
<em>This is emphasized text.</em>
D
21. What is the HTML attribute "href" used for?
The "href" attribute is used to specify the URL of the page or file
that the link goes to.
Example:
<a href="https://www.example.com/">This is a link.</a>
22 . What is the HTML attribute "alt" used for?
The "alt" attribute is used to specify alternative text for an image,
which is displayed if the image cannot be loaded or if the user is
nA
using a screen reader.
Example:
<img src="image.jpg" alt="This is an image.">
23. What is the HTML attribute "title" used for?
iQ
The "title" attribute is used to specify additional information about
an element, which is displayed as a tooltip when the user hovers
over the element.
es
Example:
<a href="https://www.example.com/" title="This is a link to
example.com.">This is a link.</a>
D
24. What is the HTML attribute "class" used for?
The "class" attribute is used to specify a class name for an
element, which can be used to apply styles to multiple elements
with the same class name.
Example:
<p class="example">This is a paragraph.</p>
<style>
.example {
color: blue;
}
</style>
nA
25. What is the HTML attribute "id" used for?
The "id" attribute is used to specify a unique identifier for an
iQ
element, which can be used to apply styles to a specific element or
to link to that element from another part of the page.
Example:
es
<p id="example">This is a paragraph.</p>
<a href="#example">Link to example paragraph.</a>
<style>
D
#example {
color: blue;
}
</style>
26 .What is the HTML attribute "target" used for?
The "target" attribute is used to specify where to open the linked
document. It can be set to "_blank" to open the document in a new
window or tab, or "_self" to open the document in the same
window or tab.
Example:
<a href="https://www.example.com/" target="_blank">This is a link that
nA
opens in a new window or tab.</a>
27. What is the HTML attribute "rel" used for?
The "rel" attribute is used to specify the relationship between the
current document and the linked document. It can be set to
iQ
"nofollow" to indicate that search engines should not follow the link,
or "noopener" to prevent the linked document from accessing the
window object of the current document.
Example:
es
<a href="https://www.example.com/" rel="nofollow">This is a link with
the nofollow attribute.</a>
D
28. What is the difference between the HTML tags "<head>" and
"<body>"?
The "<head>" tag is used to contain metadata about the document,
such as the title, stylesheets, and scripts, while the "<body>" tag is
used to contain the visible content of the document.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Example Document</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
nA
<body>
<h1>Hello, world!</h1>
<p>This is some text.</p>
</body>
</html>
iQ
29. What is the purpose of the HTML tag "<meta>"?
es
The "<meta>" tag is used to provide metadata about the
document, such as the character encoding, author, and keywords.
Example:
D
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="author" content="Ayushi Jain">
<meta name="keywords" content="HTML, CSS, JavaScript">
<title>Example Document</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is some text.</p>
</body>
</html>
30. What is the difference between the HTML tags "<ol>" and "<ul>"?
nA
The "<ol>" tag is used to create an ordered list, while the "<ul>" tag
is used to create an unordered list.
Example:
iQ
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
es
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
D
</ul>
31. What is the HTML attribute "type" used for in the "<ol>" and "<ul>"
tags?
The "type" attribute is used to specify the type of list item marker to
use. For example, it can be set to "1" to use numeric markers in an
ordered list, or "disc" to use round markers in an unordered list.
Example:
<ol type="1">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
nA
</ol>
<ul type="disc">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
iQ
</ul>
es
32. What is the HTML attribute "start" used for in the "<ol>" tag?
The "start" attribute is used to specify the starting value of the
ordered list. In the example the starting will be 3 instead of 1 .
Example:
D
<ol start="3">
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ol>
33. What is the HTML tag "<li>" used for?
The "<li>" tag is used to create a list item in an ordered or
unordered list. The <li> tag can be used as an open tag also.
Example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
nA
<li>Item 3</li>
</ul>
35 What is the HTML tag "<table>" used for?
The "<table>" tag is used to create a table.
iQ
Example:
<table>
es
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>Ayushi</td>
D
<td>Jain</td>
</tr>
<tr>
<td>Palak</td>
<td>Jain</td>
</tr>
</table>
36. What is the HTML tag "<th>" used for?
The "<th>" tag is used to create a header cell in a table.
Example:
<table>
nA
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
iQ
</tr>
<tr>
<td>Jane</td>
<td>Smith</td>
es
</tr>
</table>
>
D
37. What is the HTML tag "<tr>" used for?
The "<tr>" tag is used to create a table row.
Example:
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Smith</td>
nA
</tr>
</table>
iQ
38. What is the HTML tag "<td>" used for?
The "<td>" tag is used to create a table cell.
<39. What is the difference between the HTML tags "<thead>" and
es
"<tbody>"?
The "<thead>" tag is used to contain the header rows of a table,
while the "<tbody>" tag is used to contain the body rows of a table.
D
Example:
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Smith</td>
</tr>
nA
</tbody>
</table>
40. What is the HTML tag "<colgroup>" used for?
iQ
The "<colgroup>" tag is used to group columns in a table together
so that they can be styled or have attributes applied to them.
Example:
es
<table>
<colgroup>
<col style="background-color: yellow;">
D
<col span="2" style="background-color: green;">
</colgroup>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
</table>
41. What is the HTML attribute "colspan" used for?
nA
The "colspan" attribute is used to specify the number of columns a
table cell should span across.
Example:
<table>
iQ
<tr>
<td colspan="2">This cell spans two columns.</td>
<td>Third column</td>
</tr>
</table>
es
42. What is the HTML attribute "rowspan" used for?
D
The "rowspan" attribute is used to specify the number of rows a
table cell should span across.
Example:
<table>
<tr>
<td rowspan="2">This cell spans two rows.</td>
<td>Second column</td>
</tr>
<tr>
<td>Third column</td>
</tr>
</table>
43. What is the HTML tag "<form>" used for?
The "<form>" tag is used to create an HTML form for user input.
nA
Example:
<form>
<label for="name">Name:</label>
iQ
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
es
44. What is the HTML attribute "action" used for?
D
The "action" attribute is used to specify the URL where form data
should be sent.
Example:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
45. What is the HTML attribute "method" used for?
nA
The "method" attribute is used to specify the HTTP method used to
send the form data.
Example:
iQ
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
es
<input type="submit" value="Submit">
</form>
46. What is the HTML tag "<input>" used for?
D
The "<input>" tag is used to create various types of form fields,
such as text fields, checkboxes, radio buttons, and more.
Example:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
47. What is the HTML attribute "placeholder" used for?
The "placeholder" attribute is used to provide a hint or
example of what should be entered in a form field.
nA
Example:
<input type="text" placeholder="Enter your name">
iQ
48. What is the HTML attribute "required" used for?
The "required" attribute is used to specify that a form field
es
must be filled out before the form can be submitted.
Example:
D
<input type="email" name="email" required>
49 . What is the HTML tag "<select>" used for?
The "<select>" tag is used to create a drop-down list for
selecting one or more options. In <option> tag is for the option of
the list
Example:
<select name="cars">
nA
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
iQ
50. What is the HTML tag "<textarea>" used for?
es
The "<textarea>" tag is used to create a multi-line text input
field.
Example:
D
<textarea name="message" rows="4" cols="50">
Enter your message here.
</textarea>
51 .What is the HTML attribute "disabled" used for?
The "disabled" attribute is used to disable a form field so that
it cannot be edited or selected.
Example:
nA
<input type="text" name="username" disabled>
52. What is the HTML attribute "readonly" used for?
iQ
The "readonly" attribute is used to make a form field read-only
so that it can be viewed but not edited.
es
Example:
<input type="text" name="username" value="john_doe"
readonly>
D
53 What is the HTML tag "<label>" used for?
The "<label>" tag is used to associate a label with a form field.
Example:
<label for="username">Username:</label>
<input type="text" id="username" name="username">
54 . What is the HTML tag "<button>" used for?
The "<button>" tag is used to create a clickable button in a
nA
form.
Example:
iQ
<button type="submit">Submit</button>
55. What is the HTML attribute "type" used for?
es
The "type" attribute is used to specify the type of input for a
form field.
D
Example:
<input type="text" name="username">
56 What is the HTML attribute "value" used for?
The "value" attribute is used to set the default value of a form
field.
Example:
<input type="text" name="username" value="kumar K">
nA
57 .What is the HTML attribute "src" used for?
The "src" attribute is used to specify the source URL of an
iQ
image or other media file.
Example:
es
<img src="image.jpg" alt="A beautiful landscape">
D
58 .What is the HTML tag "<a>" used for?
The "<a>" tag is used to create a hyperlink to another web
page or a specific location within a page.
Example:
<a href="https://www.example.com/">Example</a>
nA
iQ
es
D
D
es
iQ
nA