Table of Contents
HTML interview questions, for freshers. Here are 150+ different angle questions & answers related to HTML. Html basic to advanced tutorial Know all Things in HTML.
HTML Interview Question & Answare
Here are some common html interview questions for freshers along with their answers:
Basic HTML Questions:
- What is HTML?
- HTML stands for HyperText Markup Language. It is the standard markup language for creating web pages.
- What are the main components of an HTML document?
- The main components are the HTML tags, content, and attributes.
- What is an HTML tag?
- An HTML tag is a set of characters that defines the structure and format of content in a web page.
- What is the basic structure of an HTML document?
- The basic structure consists of the
<!DOCTYPE html>
declaration,<html>
element,<head>
element, and<body>
element.
- The basic structure consists of the
- What is the purpose of the
<!DOCTYPE html>
declaration?- It specifies the document type and helps browsers render the web page correctly.
- What is the difference between HTML and XHTML?
- XHTML is a stricter and more XML-like version of HTML, requiring well-formed documents and lowercase tags.
- What is the purpose of the
<meta>
tag?- The
<meta>
tag is used to provide metadata about the HTML document, such as character set, page description, keywords, author, etc.
- The
- What are void elements in HTML?
- Void elements are elements that do not have closing tags, such as
<br>
,<img>
, and<input>
.
- Void elements are elements that do not have closing tags, such as
- What is semantic HTML?
- Semantic HTML refers to using HTML elements based on their meaning and purpose rather than just for presentation.
- Explain the difference between
<div>
and<span>
tags.<div>
is a block-level element used for grouping and structuring content, while<span>
is an inline element used for applying styles or grouping inline elements.
HTML Elements and Attributes:
- What are block-level elements?
- Block-level elements are elements that typically start on a new line and take up the full width available, such as
<div>
,<p>
, and<h1>
.
- Block-level elements are elements that typically start on a new line and take up the full width available, such as
- What are inline elements?
- Inline elements are elements that do not start on a new line and only take up as much width as necessary, such as
<span>
,<a>
, and<strong>
.
- Inline elements are elements that do not start on a new line and only take up as much width as necessary, such as
- Explain the difference between
<strong>
and<b>
.<strong>
is a semantic element used to indicate strong importance, while<b>
is a presentational element used to make text bold.
- What is the purpose of the
alt
attribute in the<img>
tag?- The
alt
attribute provides alternative text for an image, which is displayed if the image fails to load or for accessibility purposes.
- The
- How do you create a hyperlink in HTML?
- You create a hyperlink using the
<a>
(anchor) tag with thehref
attribute, which specifies the URL of the link.
- You create a hyperlink using the
- What does the
target="_blank"
attribute do in an anchor tag?- It opens the linked document in a new browser window or tab.
- What is the purpose of the
rel
attribute in the<a>
tag?- The
rel
attribute specifies the relationship between the current document and the linked document.
- The
- How do you create an ordered list in HTML?
- You create an ordered list using the
<ol>
(ordered list) tag, with each list item represented by the<li>
(list item) tag.
- You create an ordered list using the
- What is the purpose of the
<table>
tag?- The
<table>
tag is used to create a table in HTML for displaying tabular data.
- The
- What are the three types of lists in HTML?HTML5 Features:
- Ordered lists (
<ol>
), unordered lists (<ul>
), and definition lists (<dl>
).
- Ordered lists (
HTML Forms:
- What is the purpose of the
<form>
tag?- The
<form>
tag is used to create an HTML form for collecting user input.
- The
- How do you create text input fields in HTML?
- You create text input fields using the
<input>
tag with thetype="text"
attribute.
- You create text input fields using the
- Explain the purpose of the
name
attribute in form elements.- The
name
attribute is used to identify form data when the form is submitted.
- The
- What is the difference between the
GET
andPOST
methods in form submission?GET
submits form data in the URL, whilePOST
submits form data in the HTTP request body.GET
has a limit on the amount of data that can be sent, whilePOST
does not.
- How do you create a dropdown list in HTML?
- You create a dropdown list using the
<select>
tag with<option>
tags for each selectable item.
- You create a dropdown list using the
- What is the purpose of the
multiple
attribute in a dropdown list?- The
multiple
attribute allows users to select multiple options from the dropdown list.
- The
- How do you create radio buttons and checkboxes in HTML?
- Radio buttons are created using the
<input>
tag withtype="radio"
, and checkboxes are created using<input>
withtype="checkbox"
.
- Radio buttons are created using the
- Explain the purpose of the
<label>
tag in forms.- The
<label>
tag associates a label with a form element, making it more accessible and easier to interact with.
- The
- What is the
required
attribute used for in HTML forms?- The
required
attribute specifies that an input field must be filled out before submitting the form.
- The
- How do you create a textarea in HTML?
- You create a textarea using the
<textarea>
tag.
- You create a textarea using the
HTML5 Features:
- What are the new semantic elements introduced in HTML5?
- Semantic elements such as
<header>
,<footer>
,<nav>
,<article>
,<section>
, and<aside>
.
- Semantic elements such as
- What is the purpose of the
<canvas>
element in HTML5?- The
<canvas>
element is used for drawing graphics, animations, or other visual images on the fly using JavaScript.
- The
- Explain the purpose of the
<video>
and<audio>
elements in HTML5.- The
<video>
element is used to embed video content in a web page, while the<audio>
element is used to embed audio content.
- The
- What is the purpose of the
placeholder
attribute in HTML5?- The
placeholder
attribute specifies a short hint that describes the expected value of an input field.
- The
- How do you create a required field in HTML5?
- You can use the
required
attribute on form elements to make them required fields.
- You can use the
- Explain the purpose of the
contenteditable
attribute in HTML5.- The
contenteditable
attribute allows users to edit the content of an element directly within the browser.
- The
- What is the purpose of the
<progress>
element in HTML5?- The
<progress>
element represents the progress of a task, such as the completion of a download.
- The
- What is the purpose of the
<details>
and<summary>
elements in HTML5?- The
<details>
element is used to create a disclosure widget that can be toggled to show or hide additional content, and the<summary>
element provides a summary or label for the content within<details>
.
- The
- What is the purpose of the
autocomplete
attribute in HTML5?- The
autocomplete
attribute specifies whether a form field should have autocomplete enabled or disabled.
- The
- How do you create a date input field in HTML5?
- You create a date input field using the
<input>
tag withtype="date"
.
- You create a date input field using the
HTML Structure and Semantics:
- What is the purpose of the
<header>
element?- The
<header>
element typically contains introductory content or navigational links for its parent section or document.
- The
- Explain the purpose of the
<footer>
element.- The
<footer>
element typically contains footer information or links for its parent section or document.
- The
- What is the purpose of the
<nav>
element?- The
<nav>
element is used to define a block of navigation links.
- The
- How do you create a section in HTML?
- You create a section using the
<section>
tag to define a thematic grouping of content.
- You create a section using the
- What is the purpose of the
<article>
element?- The
<article>
element is used to define a self-contained piece of content that could be distributed and reused independently.
- The
- Explain the purpose of the
<aside>
element.- The
<aside>
element is used to define content that is tangentially related to the content around it, such as sidebars or pull quotes.
- The
- How do you create a header in HTML?
- You create a header using the
<header>
tag, typically at the beginning of a document or section.
- You create a header using the
- What is the purpose of the
<hgroup>
element?- The
<hgroup>
element is used to group multiple heading elements (<h1>
to<h6>
) when they are consecutive and share the same parent element.
- The
- Explain the purpose of the
<main>
element in HTML5.- The
<main>
element represents the main content of the document or a specific section of the document.
- The
- What is the purpose of the
<figure>
and<figcaption>
elements?- The
<figure>
element is used to encapsulate media content such as images, videos, diagrams, etc., while the<figcaption>
element provides a caption for the content within<figure>
.
- The
HTML Formatting and Styling:
- What is the purpose of the
<style>
element in HTML?- The
<style>
element is used to define CSS styles directly within an HTML document.
- The
- How do you create bold text in HTML?
- You create bold text using the
<strong>
or<b>
tags.
- You create bold text using the
- How do you create italicized text in HTML?
- You create italicized text using the
<em>
or<i>
tags.
- You create italicized text using the
- Explain the purpose of the
<mark>
element.- The
<mark>
element is used to highlight or mark portions of text within the document.
- The
- How do you create superscript and subscript text in HTML?
- Superscript text is created using the
<sup>
tag, while subscript text is created using the<sub>
tag.
- Superscript text is created using the
- What is the purpose of the
<pre>
element?- The
<pre>
element defines preformatted text, preserving both spaces and line breaks.
- The
- How do you create a line break in HTML?
- You create a line break using the
<br>
tag.
- You create a line break using the
- Explain the purpose of the
<blockquote>
element.- The
<blockquote>
element is used to indicate that the enclosed text is a longer quotation from another source.
- The
- What is the purpose of the
<abbr>
element?- The
<abbr>
element is used to define an abbreviation or acronym, optionally providing the full term for clarification.
- The
- How do you create a horizontal rule in HTML?
- You create a horizontal rule using the
<hr>
tag.
- You create a horizontal rule using the
HTML Links and Navigation:
- What is the purpose of the
href
attribute in the<a>
tag?- The
href
attribute specifies the URL of the linked document or resource.
- The
- How do you create a link that opens in a new tab or window?
- You create such a link by adding the
target="_blank"
attribute to the<a>
tag.
- You create such a link by adding the
- Explain the purpose of the
rel="nofollow"
attribute in links.- The
rel="nofollow"
attribute tells search engines not to follow the linked page, which is commonly used for user-generated content or paid links to avoid influencing search rankings.
- The
- What is the purpose of the
id
attribute in HTML?- The
id
attribute provides a unique identifier for an element, which can be used for styling, scripting, or linking within the same page.
- The
- How do you create an anchor link within the same page?
- You create an anchor link by using the
<a>
tag with thehref
attribute set to#
followed by theid
of the target element.
- You create an anchor link by using the
- What is the purpose of the
target
attribute in the<a>
tag?- The
target
attribute specifies where to open the linked document, such as in a new window, tab, or frame.
- The
- How do you create a mailto link in HTML?
- You create a mailto link using the
<a>
tag with thehref
attribute set tomailto:
followed by the email address.
- You create a mailto link using the
- What is the purpose of the
<base>
element in HTML?- The
<base>
element specifies the base URL for all relative URLs within a document.
- The
- Explain the purpose of the
download
attribute in the<a>
tag.- The
download
attribute specifies that the target will be downloaded when a user clicks on the link, instead of navigating to it.
- The
- How do you create a link to an external stylesheet in HTML?
- You create a link to an external stylesheet using the
<link>
tag with therel="stylesheet"
attribute and thehref
attribute specifying the URL of the stylesheet.
- You create a link to an external stylesheet using the
HTML Images and Media:
- What is the purpose of the
<img>
element in HTML?- The
<img>
element is used to embed images in a web page.
- The
- How do you specify the source of an image in HTML?
- You specify the source of an image using the
src
attribute in the<img>
tag.
- You specify the source of an image using the
- Explain the purpose of the
alt
attribute in the<img>
tag.- The
alt
attribute provides alternative text for an image, which is displayed if the image fails to load or for accessibility purposes.
- The
- What is the purpose of the
width
andheight
attributes in the<img>
tag?- The
width
andheight
attributes specify the width and height of the image in pixels, respectively.
- The
- How do you create an image map in HTML?
- You create an image map using the
<map>
tag to define clickable areas on an image, and the<area>
tag to define the clickable areas and their associated actions.
- You create an image map using the
- What is the purpose of the
<video>
element in HTML5?- The
<video>
element is used to embed video content in a web page.
- The
- How do you specify multiple video sources for different formats in HTML5?
- You specify multiple video sources using multiple
<source>
tags within the<video>
element, each with a different format andsrc
attribute.
- You specify multiple video sources using multiple
- Explain the purpose of the
controls
attribute in the<video>
tag.- The
controls
attribute displays built-in controls for the video player, such as play, pause, volume, and fullscreen buttons.
- The
- What is the purpose of the
<audio>
element in HTML5?- The
<audio>
element is used to embed audio content in a web page.
- The
- How do you specify multiple audio sources for different formats in HTML5?
- You specify multiple audio sources using multiple
<source>
tags within the<audio>
element, each with a different format andsrc
attribute.
- You specify multiple audio sources using multiple
HTML Tables:
- What is the purpose of the
<table>
element in HTML?- The
<table>
element is used to create a table for displaying tabular data.
- The
- How do you create rows and columns in an HTML table?
- You create rows using the
<tr>
(table row) tag and columns using the<td>
(table data) tag within the<tr>
tag.
- You create rows using the
- Explain the purpose of the
<th>
element in HTML tables.- The
<th>
element is used to define header cells in a table, which typically contain column or row labels.
- The
- What is the purpose of the
colspan
androwspan
attributes in HTML tables?- The
colspan
attribute specifies the number of columns a cell should span, while therowspan
attribute specifies the number of rows a cell should span.
- The
- How do you create a caption for an HTML table?
- You create a caption using the
<caption>
tag within the<table>
tag.
- You create a caption using the
- What is the purpose of the
<thead>
,<tbody>
, and<tfoot>
elements in HTML tables?<thead>
is used to group the header content of the table,<tbody>
is used to group the body content of the table, and<tfoot>
is used to group the footer content of the table.
- How do you create a border around an HTML table?
- You create a border by using CSS to apply styling to the table, such as setting the
border
property.
- You create a border by using CSS to apply styling to the table, such as setting the
- Explain the purpose of the
border
attribute in the<table>
tag.- The
border
attribute specifies the width of the border around the table and its cells, but it’s not recommended to use it. Styling with CSS is preferred.
- The
- How do you align content within table cells in HTML?
- You align content within table cells using CSS properties such as
text-align
for horizontal alignment andvertical-align
for vertical alignment.
- You align content within table cells using CSS properties such as
- What is the purpose of the
cellpadding
andcellspacing
attributes in HTML tables?- The
cellpadding
attribute specifies the space between the content of a cell and its border, whilecellspacing
specifies the space between cells.
- The
HTML Forms and Input Elements:
- What is the purpose of the
<form>
element in HTML?- The
<form>
element is used to create an HTML form for collecting user input.
- The
- How do you create text input fields in HTML?
- You create text input fields using the
<input>
tag with thetype="text"
attribute.
- You create text input fields using the
- Explain the purpose of the
name
attribute in form elements.- The
name
attribute is used to identify form data when the form is submitted.
- The
- What is the difference between the
GET
andPOST
methods in form submission?GET
submits form data in the URL, whilePOST
submits form data in the HTTP request body.GET
has a limit on the amount of data that can be sent, whilePOST
does not.
- How do you create a dropdown list in HTML?
- You create a dropdown list using the
<select>
tag with<option>
tags for each selectable item.
- You create a dropdown list using the
- What is the purpose of the
multiple
attribute in a dropdown list?- The
multiple
attribute allows users to select multiple options from the dropdown list.
- The
- How do you create radio buttons and checkboxes in HTML?
- Radio buttons are created using the
<input>
tag withtype="radio"
, and checkboxes are created using<input>
withtype="checkbox"
.
- Radio buttons are created using the
- Explain the purpose of the
<label>
tag in forms.- The
<label>
tag associates a label with a form element, making it more accessible and easier to interact with.
- The
- What is the
required
attribute used for in HTML forms?- The
required
attribute specifies that an input field must be filled out before submitting the form.
- The
- How do you create a textarea in HTML? – You create a textarea using the
<textarea>
tag. - What is the purpose of the
placeholder
attribute in HTML5? – Theplaceholder
attribute specifies a short hint that describes the expected value of an input field. - How do you create a required field in HTML5? – You can use the
required
attribute on form elements to make them required fields. - Explain the purpose of the
contenteditable
attribute in HTML5. – Thecontenteditable
attribute allows users to edit the content of an element directly within the browser. - What is the purpose of the
<progress>
element in HTML5? – The<progress>
element represents the progress of a task, such as the completion of a download. - What is the purpose of the
<details>
and<summary>
elements in HTML5? – The<details>
element is used to create a disclosure widget that can be toggled to show or hide additional content, and the<summary>
element provides a summary or label for the content within<details>
. - What is the purpose of the
autocomplete
attribute in HTML5? – Theautocomplete
attribute specifies whether a form field should have autocomplete enabled or disabled. - How do you create a date input field in HTML5? – You create a date input field using the
<input>
tag withtype="date"
. - What is the purpose of the
<header>
element? – The<header>
element typically contains introductory content or navigational links for its parent section or document. - Explain the purpose of the
<footer>
element. – The<footer>
element typically contains footer information or links for its parent section or document. - What is the purpose of the
<nav>
element? – The<nav>
element is used to define a block of navigation links. - How do you create a section in HTML? – You create a section using the
<section>
tag to define a thematic grouping of content. - What is the purpose of the
<article>
element? – The<article>
element is used to define a self-contained piece of content that could be distributed and reused independently. - Explain the purpose of the
<aside>
element. – The<aside>
element is used to define content that is tangentially related to the content around it, such as sidebars or pull quotes. - How do you create a header in HTML? – You create a header using the
<header>
tag, typically at the beginning of a document or section. - What is the purpose of the
<hgroup>
element? – The<hgroup>
element is used to group multiple heading elements (<h1>
to<h6>
) when they are consecutive and share the same parent element. - Explain the purpose of the
<main>
element in HTML5. – The<main>
element represents the main content of the document or a specific section of the document. - What is the purpose of the
<figure>
and<figcaption>
elements? – The<figure>
element is used to encapsulate media content such as images, videos, diagrams, etc., while the<figcaption>
element provides a caption for the content within<figure>
. - What is the purpose of the
<style>
element in HTML? – The<style>
element is used to define CSS styles directly within an HTML document. - How do you create bold text in HTML? – You create bold text using the
<strong>
or<b>
tags. - How do you create italicized text in HTML? – You create italicized text using the
<em>
or<i>
tags. - Explain the purpose of the
<mark>
element. – The<mark>
element is used to highlight or mark portions of text within the document. - How do you create superscript and subscript text in HTML? – Superscript text is created using the
<sup>
tag, while subscript text is created using the<sub>
tag. - What is the purpose of the
<pre>
element? – The<pre>
element defines preformatted text, preserving both spaces and line breaks. - How do you create a line break in HTML? – You create a line break using the
<br>
tag. - Explain the purpose of the
<blockquote>
element. – The<blockquote>
element is used to indicate that the enclosed text is a longer quotation from another source. - What is the purpose of the
<abbr>
element? – The<abbr>
element is used to define an abbreviation or acronym, optionally providing the full term for clarification. - How do you create a horizontal rule in HTML? – You create a horizontal rule using the
<hr>
tag. - What is the purpose of the
href
attribute in the<a>
tag? – Thehref
attribute specifies the URL of the linked document or resource. - How do you create a link that opens in a new tab or window? – You create such a link by adding the
target="_blank"
attribute to the<a>
tag. - Explain the purpose of the
rel="nofollow"
attribute in links. – Therel="nofollow"
attribute tells search engines not to follow the linked page, which is commonly used for user-generated content or paid links to avoid influencing search rankings. - What is the purpose of the
id
attribute in HTML? – Theid
attribute provides a unique identifier for an element, which can be used for styling, scripting, or linking within the same page. - How do you create an anchor link within the same page? – You create an anchor link by using the
<a>
tag with thehref
attribute set to#
followed by theid
of the target element. - What is the purpose of the
target
attribute in the<a>
tag? – Thetarget
attribute specifies where to open the linked document, such as in a new window, tab, or frame. - How do you create a mailto link in HTML? – You create a mailto link using the
<a>
tag with thehref
attribute set tomailto:
followed by the email address. - What is the purpose of the
<base>
element in HTML? – The<base>
element specifies the base URL for all relative URLs within a document. - Explain the purpose of the
download
attribute in the<a>
tag. – Thedownload
attribute specifies that the target will be downloaded when a user clicks on the link, instead of navigating to it. - How do you create a link to an external stylesheet in HTML? – You create a link to an external stylesheet using the
<link>
tag with therel="stylesheet"
attribute and thehref
attribute specifying the URL of the stylesheet. - What is the purpose of the
<img>
element in HTML? – The<img>
element is used to embed images in a web page. - How do you specify the source of an image in HTML? – You specify the source of an image using the
src
attribute in the<img>
tag. - Explain the purpose of the
alt
attribute in the<img>
tag. – Thealt
attribute provides alternative text for an image, which is displayed if the image fails to load or for accessibility purposes. - What is the purpose of the
width
andheight
attributes in the<img>
tag? – Thewidth
andheight
attributes specify the width and height of the image in pixels, respectively. - How do you create an image map in HTML? – You create an image map using the
<map>
tag to define clickable areas on an image, and the<area>
tag to define the clickable areas and their associated actions. - What is the purpose of the
<video>
element in HTML5? – The<video>
element is used to embed video content in a web page. - How do you specify multiple video sources for different formats in HTML5? – You specify multiple video sources using multiple
<source>
tags within the<video>
element, each with a different format andsrc
attribute. - Explain the purpose of the
controls
attribute in the<video>
tag. – Thecontrols
attribute displays built-in controls for the video player, such as play, pause, volume, and fullscreen buttons. - What is the purpose of the
<audio>
element in HTML5? – The<audio>
element is used to embed audio content in a web page. - How do you specify multiple audio sources for different formats in HTML5? – You specify multiple audio sources using multiple
<source>
tags within the<audio>
element, each with a different format andsrc
attribute. - What is the purpose of the
<iframe>
element in HTML? – The<iframe>
element is used to embed another HTML document within the current document. - Explain the purpose of the
srcdoc
attribute in the<iframe>
tag. – Thesrcdoc
attribute specifies the HTML content to display within the<iframe>
element, allowing inline HTML content without requiring an external file. - What is the purpose of the
<embed>
element in HTML? – The<embed>
element is used to embed external content such as multimedia or plugins directly within the HTML document.
HTML Semantic Elements and SEO:
- What are semantic HTML elements? – Semantic HTML elements are elements that convey meaning beyond just presentation, making it easier for search engines and screen readers to understand the structure and content of a web page.
- Why are semantic HTML elements important for SEO? – Semantic HTML elements help search engines better understand the content and structure of a web page, which can improve search engine rankings and accessibility.
- Give examples of semantic HTML elements. – Examples include
<header>
,<footer>
,<nav>
,<article>
,<section>
,<aside>
,<main>
,<figure>
,<figcaption>
, etc. - How do you use the
<meta>
element to improve SEO? – You can use the<meta>
element to provide metadata about the HTML document, such as keywords, descriptions, authorship, and viewport settings, which can help improve search engine rankings and click-through rates. - Explain the purpose of the
title
element in HTML. – The<title>
element defines the title of the document, which appears in the browser’s title bar or tab and is important for SEO and bookmarking. - How do you use heading elements (
<h1>
to<h6>
) for SEO? – Heading elements should be used to structure content hierarchically, with<h1>
representing the main heading and subsequent levels indicating subheadings. Proper use of headings can improve SEO by providing context and structure to the content. - What is the purpose of the
alt
attribute in the<img>
tag for SEO? – Thealt
attribute provides alternative text for images, which is important for SEO as it helps search engines understand the content of images and improves accessibility for users with disabilities. - Explain the importance of using descriptive URLs for SEO. – Descriptive URLs containing relevant keywords can improve SEO by providing context to both users and search engines about the content of a web page. They also tend to be more user-friendly and easier to remember.
- What is the purpose of the
rel="canonical"
link element for SEO? – Therel="canonical"
link element specifies the preferred version of a web page when multiple versions with similar content exist, helping to avoid duplicate content issues and consolidate ranking signals for search engines. - How do you use semantic HTML elements to improve accessibility? – Semantic HTML elements provide meaning and structure to the content, which can improve accessibility for users with disabilities by making it easier for screen readers to interpret and navigate the content.
Conclusion:
These HTML interview questions and answers cover a wide range of topics, including basic syntax, semantics, formatting, links and navigation, images and media, tables, forms, best practices, and recent developments in HTML5. By studying and understanding these questions, you’ll be better prepared for HTML interviews and have a solid foundation for building web applications. Keep practicing and exploring new concepts to enhance your HTML skills further. Good luck!