HTML Question Answers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

HTML Interview

Questions & Answers

100+ HTML Questions & Answers for your


interview preparation.

By: www.deepdeveloper.in
Here are 100+ HTML questions and answers that you
can use for interview preparation:

Q1. What is HTML?


Answer: HTML stands for HyperText Markup Language. It
is the standard markup language for creating web pages and
web applications.

Q.2 What is a tag in HTML?


Answer: A tag in HTML is a markup element used to define
the structure and content of a web page. It consists of an
opening tag, content, and a closing tag.

Q.3 What is the purpose of the "DOCTYPE" declaration


in HTML?
Answer: The "DOCTYPE" declaration in HTML is used to
define the version of HTML being used in a web page and to
ensure proper rendering of the page by web browsers.

Q.4 What are some common HTML tags used for text
formatting?
Answer: Some common HTML tags used for text formatting
are <b> for bold, <i> for italic, <u> for underline, and <br> for
line break.

Q.5 What is the difference between <div> and <span> in


HTML?
Answer: <div> and <span> are both container elements in
HTML, but <div> is a block-level element, while <span> is an
inline element. This means that <div> creates a new block-
level element, which takes up the entire width of its parent
container, while <span> only takes up the width of its
content.
1
Q.6 What is the purpose of the "alt" attribute in the
<img> tag in HTML?
Answer: The "alt" attribute in the <img> tag is used to
provide alternative text for an image, which is displayed if
the image cannot be loaded or read by screen readers for
accessibility purposes.

Q.7 How do you create a hyperlink in HTML?


Answer: Hyperlinks can be created in HTML using the <a>
tag, with the "href" attribute specifying the URL of the
target page.
For example: <a href="https://example.com">Link Text</a>

Q.8 What is the purpose of the "target" attribute in


the <a> tag in HTML?
Answer: The "target" attribute in the <a> tag is used to
specify where the linked document should be opened. For
example, "_blank" will open the link in a new tab or window,
while "_self" will open the link in the same window/tab.

Q.9 What are the different types of lists in HTML?


Answer: There are three types of lists in HTML: ordered
lists (<ol>), unordered lists (<ul>), and definition lists (<dl>).

Q.10 How do you create a table in HTML?


Answer: Tables can be created in HTML using the <table>
tag, with additional tags such as <tr> for table rows, <td>
for table cells, and <th> for table headers.

Q.11 What is the purpose of the "colspan" and


"rowspan" attributes in HTML tables?
Answer: The "colspan" attribute in HTML tables is used to
specify the number of columns a cell should span, while the
"rowspan" attribute is used to specify the number of rows
a cell should span.
2
Q.12 What is the purpose of the "form" tag in HTML?
Answer: The <form> tag in HTML is used to create an
interactive form on a web page, which allows users to input
data and submit it to a server for processing.

Q.13 What are some common form input types in HTML


Answer: Some common form input types in HTML are text
input (<input type="text">), password input (<input
type="password">), checkbox input (<input
type="checkbox">), radio input (<input type="radio">), and
submit button (<input type="submit">).

Q.14 What is the purpose of the "required" attribute in


HTML form inputs?
Answer: The "required" attribute in HTML form inputs is
used to specify that a particular input field must be filled
out by the user before the form can be submitted. If the
"required" attribute is added to an input field, the form
will not be submitted until that field has been filled out.

Q.15 What is the purpose of the "placeholder"


attribute in HTML form inputs?
Answer: The "placeholder" attribute in HTML form inputs
is used to provide a hint or example of the expected input
format for the user. The text specified in the
"placeholder" attribute is displayed in the input field until
the user enters their own input.

Q.16 How do you include comments in HTML?


Answer: Comments in HTML can be included using the
<!-- --> syntax. Anything placed between these tags will
not be rendered on the web page and can be used to add
comments or notes for developers.

3
Q.17 What is the purpose of the "id" attribute in
HTML?
Answer: The "id" attribute in HTML is used to uniquely
identify an element on a web page. It is commonly used for
scripting purposes or for applying styles using CSS.

Q.18 What is the purpose of the "class" attribute in


HTML?
Answer: The "class" attribute in HTML is used to group
elements that share similar characteristics or styles. It is
commonly used for applying styles using CSS or for
JavaScript manipulation.

Q.19 How do you include an external CSS file in an


HTML document?
Answer: An external CSS file can be included in an HTML
document using the <link> tag in the <head> section of the
HTML document.
For example: <link rel="stylesheet" href="styles.css">

Free Courses, E-books,


Components and Project Source
Files Join Our Telegram Channel

4
Q.20 What is the purpose of the "form" element in
HTML?
Answer: The <form> element in HTML is used to create a
container for a collection of form elements, such as input
fields, buttons, checkboxes, etc. It is used to collect user
input data and send it to the server for processing.

Q.21 What is the purpose of the "target" attribute in


the <a> tag in HTML?
Answer: The "target" attribute in the <a> tag in HTML is
used to specify where the linked document should be
opened when the user clicks on the link. Common values for
the "target" attribute include "_blank" (to open the link in
a new window or tab), "_self" (to open the link in the same
frame or window), "_parent" (to open the link in the parent
frame), and "_top" (to open the link in the top-level frame).

Q.22 What is the purpose of the "fieldset" element in


HTML?
Answer: The <fieldset> element in HTML is used to group
related form elements together and create a visual
grouping or a fieldset with a legend. It is commonly used to
group form elements such as input fields, checkboxes, and
radio buttons that are related to a specific topic or section
of a form.

Q.23 What is the purpose of the "datalist" element in


HTML?
Answer: The <datalist> element in HTML is used to provide
a list of predefined options for an input field. It is used in
conjunction with the <input> element with the "list"
attribute, which specifies the ID of the <datalist> element.
When the user types in the input field, they can select an
option from the list of predefined options provided by the
<datalist> element.
5
Q.24 What is the purpose of the "data-" attributes in
HTML?
Answer: The "data-" attributes in HTML are used to store
private data private to the page or application. These
attributes can be used to attach custom data private to
the page or application to HTML elements, which can then
be accessed and manipulated using JavaScript or CSS.

Q.25 What is the purpose of the "iframe" element in


HTML?
Answer: The <iframe> element in HTML is used to embed
another HTML document or web page within the current
HTML document. It is commonly used to display external
content, such as maps, videos, or other web pages, within a
container on a web page.

Q.26 What is the purpose of the "meta" element in


HTML?
Answer: The <meta> element in HTML is used to provide
metadata or additional information about an HTML
document. This information includes things like the
character encoding, viewport settings, authorship, and
description of the web page, which can be used by
browsers, search engines, and other web tools.

Q27. What is the purpose of the "aside" element in


HTML?
Answer: The <aside> element in HTML is used to define
content that is tangentially related to the content around
it, such as a sidebar, a pull quote, or a related article. It is
typically used for content that is not directly part of the
main content of a web page.

6
For Full PDF
Visit: https://deepdeveloper.in/

Free Courses, E-books,


Components and Project Source
Files Join Our Telegram Channel

Follow on Social Media

You might also like