30 Top HTML Interview Questions and Answers
30 Top HTML Interview Questions and Answers
In this tutorial, we have covered HTML interview questions which include both the basic as well
as advanced portions of HTML which are helpful for freshers as well as experienced candidates.
HTML is a very basic language from which we begin our work on Web development.
Very strong knowledge of HTML is highly recommended to crack the interviews for any web
development posts. I hope this informative tutorial would help you much to clear the interviews
successfully at the first attempt.
Given below is the list of most popular HTML interview questions with the answers and
examples codes for your easy understanding.
Let’s Start!!
Answer: Hypertext Markup Language or HTML is a markup language that is used to create
website templates or WebPages to present the content on the World Wide Web.
HTML pages are saved by adding .html or .html in web page name.
<html>
<head>
<title></title>
</head>
<body>
</body></html>
Answer: HTML5 is the latest or updated version of the markup language that defines HTML.
Q #5) Name some new features which were not present in HTML but are added to
HTML5?
Q #6) What is Anchor tag and how can you open an URL into a new tab when clicked?
Answer: Anchor tag in HTML is used to link between two sections or two different web pages
or website templates.
To open an URL into a new tab in the browser upon a click, we need to add target attribute equal
to _blank.
Q #7) Write an HTML code to form a table to show the below values in a tabular form with
heading as Roll No., Student name, Subject Name, and values as
1. Ram, Physics
2. Shyam, Math
3. Murli, Chemistry
Answer: To represent the above values in an HTML table format, the code will be:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</style>
</head>
<body>
<table >
<tr>
</tr>
<tr>
<td> 1 </td>
<td>Ram</td>
</tr>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
Output:
Answer: Semantic elements are HTML elements that represent its meaning to the browser and
developer about its contents.
For Example – p tag represents a paragraph, a tag represents anchor tag, form tag, table tag,
article tag and many more are semantic elements in HTML. Whereas, div tag, span tag, bold tag
are not semantic elements.
Answer: The HTML tag contains a field inside their tag which is called attributes of that tag.
For Example:
<input type=” text”> here in this tag type is input tag attributes.
Q #10) Can we modify the attribute’s value of the HTML tag dynamically?
Answer: Yes, we can modify the value of the attributes by using JavaScript.
Below is the input element whose attribute will be modified from text to password, JS code to
modify the attribute value:
document.getElementById(“inputField”).attr(“type”, “password”);
The commented outlines will not be shown in the browser. To comment a line, the line should
start by this <!– and end by this –>. Comments can be of one line or of multiple lines.
For Example:
Answer: Block elements are the blocks that take the full available width and always start from a
new line. It will stretch itself to the full available width of the available container width. Block-
level elements are <div>, <p>, <img>, <section> and many more.
Inline elements are the elements that will only take the width that is required to fit into the
container.
For Example, take the flow of text on the page. When the line of the text takes the full width of
the container it wraps itself into a new line and again goes in the same way.
Whereas, the inline element will take only that much space or width that it is needed for them.
Inline elements are <span>, <label>, <a>, <b> and many more.
Answer: Yes, we can change inline elements into block-level elements by adding display equal
to block in its CSS tag. Writing it will change the inline elements into block elements and then
inline elements will also take the full width of the container.
display: block;
Answer: All modern browsers support HTML5 elements except some old browsers. But
fortunately, most of the browsers will take html5 elements as inline elements.
Answer: <br> tags are used to enter a new line into the HTML contents. These tags are
generally used to separate two different lines of text between each other.
(i) DOCTYPE – It is a special tag in HTML which is always written at the top of the HTML
document, i.e. at the start of the HTML template. DOCTYPE is used to convey to the browser
about the HTML version.
<!DOCTYPE html>
(ii) HTML – After DOCTYPE tag, the HTML tag is written to start the template. All the code
will be placed into this HTMLtag. It works as the container for the whole HTML page elements.
<html>
</html>
(iii) HEAD – <head> tag is the first element inside the <html> tag. It is used to provide
information to the browser about the page and its contents.
Search Engine Optimization (SEO) techniques are written inside this tag. <title>, <meta> tags
are written inside these tag. CSS and JS external links or internal CSS and JS are also written
inside this tag.
<head>
<meta charset="UTF-8">
</head>
(iv) BODY – <body> tags are written after the closing tag of the <head> tag, i.e. after </head>.
Whatever HTML code is written inside these tags will be shown by the browser as website
content.
<body>
</body>
<head>
<meta charset="UTF-8">
<style type="text/css">
h2{
color: #1855b5;
p{
color: #3bd256;
font-weight: 600;
</style>
<script type="text/javascript">
</script>
</head>
<body>
</body>
</html>
Output:
Q #17) Why Meta tags are used in HTML?
Answer: Meta tags in HTML are used by the developer to tell the browser about the page
description, author of the template, character set, keywords and many more.
Meta tags are used for search engine optimization to tell the search engine about the page
contents.
<meta charset="UTF-8">
• Ordered List (<ol>) – An Ordered List or ol tag is the list that lists the items in an ordered way,
i.e. numbered or alphabetically.
• Unordered List (<ul>) – An Unordered List or ul tag is the list which will list the items in an
unordered way, i.e. in bulleted format or in any other format.
• Definition List (<dl>) – A Definition List or dl tag arrange the items in the way in which they are
arranged in a dictionary.
Ordered List:
<!DOCTYPE html>
<html>
<head>
</head>
<style>
h1{
color: red;
li{
color: #0070ff;
}
</style>
<body>
<ol>
<li>HTML</li>
<li>CSS</li>
<li>Bootstrap</li>
<li>JavaScript</li>
</ol>
</body>
</html>
Output:
Unordered List:
<!DOCTYPE html>
<html>
<head>
<style>
h1{
color: red;
li{
color: #0070ff;
}
</style>
</head>
<body>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>Bootstrap</li>
<li>JavaScript</li>
</ul>
</body>
</html>
Output:
Definition List:
<!DOCTYPE html>
<html>
<head>
<style>
dt{
font-weight: 600;
font-size: 25px;
color: red;
dd{
font-weight: 500;
font-size: 15px;
color: #0070ff;
</style>
</head>
<body>
<dl>
<dt><strong>HTML</strong></dt>
<dt><bold>CSS</bold></dt>
</dl>
</body>
</html>
Output:
The src attribute contains the path to the document that occupies the inline iframe.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</iframe>
</body>
</html>
Output:
Q #20) Define forms in HTML.
Answer: Forms in HTML are required when we want to collect the user information whenever a
user fills any form or provides any details and when we want to save it into our database.
<!DOCTYPE html>
<html>
<head>
<style>
form {
width: 200px;
margin: 0 auto;
p{
color: red;
font-size: 16px;
font-weight: 600;
input::placeholder{
color: blue;
button{
line-height: 20px;
text-align: center;
background: green;
border: 0;
color: #ffffff;
font-size: 14px;
margin-top: 20px;
</style>
</head>
<body>
<form >
<p>Name:</p>
<br/>
<br/>
<p>Email: </p>
<br/>
<br/>
<p>Password: </p>
<br/>
</form>
</body>
</html>
Output:
Q #21) In how many ways can a heading be written in HTML?
Answer: A heading can be defined as a block-level element that is used to give a heading to a
particular section or topic.
<!DOCTYPE html>
<html>
<head>
<style>
h1{
color: red;
h2{
color: blue;
}
h3{
color : green;
h4{
color: purple;
h5{
color: yellow;
h6{
color: orange;
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
Output:
Q #22) How can we create a hyperlink in HTML?
Answer: An anchor tag or <a> tag in HTML is used to create hyperlinks. This creates a path
between two different HTML web pages.
Answer: The required attribute is used in HTML to make the field mandatory. It forces the user
to fill that particular field to submit the form.
<!DOCTYPE html>
<html>
<body>
</div>
<script>
function myMap() {
var mapOptions = {
zoom: 10
</script>
<script src=
"https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-
916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
</body></html>
Output:
Q #25) Differentiate between HTML and XHTML.
• HTML stands for Hypertext Markup Language, whereas XHTML stands for Extensible Markup
Language.
• A static webpage is an HTML web page and dynamic web pages are XHTML.
• XHTML are more stricter than HTML.
• An XML application of HTML is defined as XHTML.
• All modern browsers support XHTML.
Answer: Web Workers is a code of JavaScript which runs in the background threads without
disturbing the performance of the page. It is used for computing-heavy tasks like an access
database or function.
SVG is resolution independent as it does not lose its quality when they are resized or zoomed.
Answer: Canvas is a pixel-based graphics and it is one of the new features of HTML5.
It provides a space in the document where we can draw graphics by using JavaScript and it is
resolution dependent, hence the quality will be affected when it’s zoomed or resized.
Example:
<!DOCTYPE html>
<html>
<body>
<script>
canvas.fillText("Canvas Example",30,60);
</script>
</body>
Q #29) Explain new form elements in HTML5.
Answer: The new form elements that were added into HTML5 are:
Answer: If we do not include the <!DOCTYPE> element in our HTML page or Document, it
will go to Quirks Mode. In this mode, the HTML element depends on the browser. Hence the
content will be displayed according to the browser.
Conclusion
These interview questions and answers will help you to crack the Web development interview
successfully. Most questions include the HTML expert’s answers during their interviews.
Hope, these interview questions would have enriched your knowledge of the HTML concept!!