HTML Interview Questions and Answers (2021) - InterviewBit
HTML Interview Questions and Answers (2021) - InterviewBit
Self-Assessment Test
This article will cover the introduction of the HTML language, basic to advanced interview questions, how
to clear HTML interviews, and some MCQs for you to solve.
Introduction:
Before starting with the interview questions on HTML Language, let’s first go through HTML, what is HTML,
the career opportunities it provides, etc.
HTML stands for Hyper Text Markup language. It is a standard text formatting language used for
developing web pages released in 1993. HTML is a language which is interpreted by the browser and it
tells the browser what to display and how to display.
HTML is a must to learn language, if anyone wants to work in the web development domain [Web
designers, Web Developers]. HTML alone is not sufficient for a web developer because HTML only defines
the structure of the data that will be rendered on the browser in a webpage, to make it visually appealing
and to make it functional, we will need to use CSS and Javascript respectively.
The latest version of HTML is HTML5. There are two main components in HTML language, Tags and
Attributes. The below image shows some basic HTML tags and attributes.
https://www.interviewbit.com/html-interview-questions/ 1/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
Interview Questions:
1. What are some of the advantages of HTML5 over its
previous versions?
Some advantages of HTML5 are:-
https://www.interviewbit.com/html-interview-questions/ 2/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
Inline elements just take up the space that is Block elements start on a new line and
absolutely necessary for the content and does consume the full width of the page
not start from a new line.Example:- <span>, available.Example:- <div>, <p>, <header>,
<a>, <strong>, <img>, <button>, <em>, <footer>, <h1>...<h6>, <form>, <table>,
<select>, <abbr>, <label>, <sub>, <cite>, <canvas>, <video>, <blockquote>, <pre>,
<abbr>, <script>, <label>, <i>, <input>, <ul>, <ol>, <figcaption>, <figure>, <hr>,
<output>, <q>, etc. <article>, <section>, etc.
Whereas, <strong> and <em> tags represents that the span of text is of strong importance or more
importance and emphatic stress respectively, than the rest of the text. These tags have semantic meaning.
The <figure> tag specifies the self-contained content, like diagrams, images, code snippets, etc. <figure>
tag is used to semantically organize the contents of an image like image, image caption, etc., whereas the
<img> tag is used to embed the picture in the HTML document.
<body> tag defines the body of the HTML document. It should always be enclosed in the <html> tag. All
the contents which needs to be displayed on the web page like images, text, audio, video, contents, using
elements like <p>, <img>, <audio>, <heading>, <video>, <div>, etc. will always be enclosed by the <body>
tag. Also, there can be only 1 body element in an HTML document and will always be after the <head> tag.
https://www.interviewbit.com/html-interview-questions/ 4/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
<map name=”workspace”>
</map>
codes.
Entity
Character Entity Name
Number
https://www.interviewbit.com/html-interview-questions/ 6/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
1, HTML, FrontEnd
2, CSS, FrontEnd
3, Python, BackEnd
Yes, it is possible using the “display” property with its value as “block”, to change the inline element into a
block-level element.
1. static: Default value. Here the element is positioned according to the normal flow of the document.
2. absolute: Here the element is positioned relative to its parent element. The final position is determined
by the values of left, right, top, bottom.
3. fixed: This is similar to absolute except here the elements are positioned relative to the <html> element.
4. relative: Here the element is positioned according to the normal flow of the document and positioned
relative to its original/ normal position.
5. initial: This resets the property to its default value.
6. inherit: Here the element inherits or takes the property of its parent.
Below are some of the display types which are rarely used:
1. table
2. inline-table
3. table-cell
4. table-column
5. table-row
6. inline-grid
7. list-item
8. inherit
9. initial
https://www.interviewbit.com/html-interview-questions/ 8/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
10. table-caption
26. How to specify the link in HTML and explain the target
attribute?
HTML provides a hyperlink - <a> tag to specify the links in a webpage. The ‘href’ attribute is used to
specify the link and the ‘target’ attribute is used to specify, where do we want to open the linked document.
The ‘target’ attribute can have the following values:
1. _self: This is a default value. It opens the document in the same window or tab as it was clicked.
2. _blank: It opens the document in a new window or tab.
3. _parent: It opens the document in a parent frame.
4. _top: It opens the document in a full-body window.
28. What is the difference between the ‘id’ attribute and the
‘class’ attribute of HTML elements?
Multiple elements in HTML can have the same class value, whereas a value of id attribute of one element
cannot be associated with another HTML element.
https://www.interviewbit.com/html-interview-questions/ 9/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
29. In how many ways can we specify the CSS styles for the
HTML element?
There are three ways in which we can specify the styles for HTML element:
1. Inline: Here we use the ‘style’ attribute inside the HTML element.
2. Internal: Here we use the <style> tag inside the <head> tag. To apply the style we bind the elements
using ‘id’ or ‘class’ attributes.
3. External: Here we use the <link> tag inside <head> tag to reference the css file into our HTML code.
Again the binding between elements and styles is done using ‘id’ or ‘class’ attributes.
30. Difference between link tag <link> and anchor tag <a>?
The anchor tag <a> is used to create a hyperlink to another webpage or to a certain part of the webpage
and these links are clickable, whereas, link tag <link> defines a link between a document and an external
resource and these are not clickable.
https://www.interviewbit.com/html-interview-questions/ 10/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
<!DOCTYPE html>
<html>
<body>
<h1>
<span>This is a demo for </span>
<u><span id="demo"></span></u>
</h1>
<script>
document.getElementById("demo").innerHTML = "script Tag"
</script>
</body>
</html>
32. When to use scripts in the head and when to use scripts in
the body?
If the scripts contain some event-triggered functions or jquery library then we should use them in the head
section. If the script writes the content on the page or is not inside a function then it should be placed
inside the body section at the bottom. In short, follow below three points:
<form action="/submit_data.php">
<label>Enter your name: </label>
<input type="text" name="name" />
<label>Enter Mobile number </label>
<input type="number" name="mobile_no"/>
<input type="submit" value="Submit">
</form>
https://www.interviewbit.com/html-interview-questions/ 11/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
<!DOCTYPE html>
<html>
<body style="padding-top:50px">
<h3 id="event_demo">0</h3>
<input type="button" onclick="myFunction()" value="Click Me" />
<input type="reset" onclick="reset()" value="Reset" />
</body>
<script>
function myFunction() {
var value = document.getElementById("event_demo").innerHTML
value = parseInt(value) + 1;
document.getElementById("event_demo").innerHTML = value;
}
function reset() {
document.getElementById("event_demo").innerHTML = 0;
}
</script>
</html>
1. Mp3
2. WAV
3. Ogg
1. If you have used inline, internal, and external all the 3 stylings in HTML for a
single element then which style will be applied?
Inline
Internal
External
<?-- -->
<!-- -->
<!-- --!>
</-- -->
3. Which of the following is correct HTML syntax for adding background color?
https://www.interviewbit.com/html-interview-questions/ 13/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
4. Which is the correct HTML syntax for adding a link to the image?
<div>
<nav>
<article>
<summary>
.hml
.xml
.html
https://www.interviewbit.com/html-interview-questions/ 14/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
.htm
True
False
tooltip
title
ref
inline-flex
flexbox
flex
grid
https://www.interviewbit.com/html-interview-questions/ 15/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
https://www.interviewbit.com/html-interview-questions/ 16/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
https://www.interviewbit.com/html-interview-questions/ 17/18
5/24/2021 HTML Interview Questions and Answers (2021) - InterviewBit
https://www.interviewbit.com/html-interview-questions/ 18/18