30 Top HTML Interview Questions And Answers [2022 LIST]

List of Most Popular HTML Interview Questions For Freshers and Experienced Professionals:

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.

HTML Interview Questions and Answers

Table of Contents:

  • Most Frequently Asked HTML Interview Questions
  • Conclusion
  • Was this helpful?
  • Recommended Reading

Most Frequently Asked HTML Interview Questions

Given below is the list of most popular HTML interview questions with the answers and examples codes for your easy understanding.

Let’s Start!!

Q #1) What does HTML stand for?

Answer: HTML stands for Hypertext Markup Language.

Q #2) Describe HTML.

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.

Q #3) Write the basic structure of the HTML template?

Answer: The basic structure of the HTML template is:

<html>       <head>                 <title></title>       </head>       <body>       </body></html>

Q #4) What is HTML5?

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?

Answer: Some new features in HTML5 include:

  • DOCTYPE declaration: <!DOCTYPE html>
  • section: Section tag defines a section in the document, such as a header, footer or in other sections of the document. It is used to define the structure of the document. <section></section>
  • header: Header tag defines the head section of the document. A header section always sticks at the top of the document. <header></header>
  • footer: Footer tag defines the footer section of the document. A footer section always sticks at the bottom of the document. <footer></footer>
  • article: Article tag defines an independent piece of the content of a document. <article> </article>
  • main: The main tag defines the main section in the document which contains the main content of the document. <main></main>
  • figcaption: Figcaption tag defines the caption for the media elements such as an image or video. <figcaption></figcaption>

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.

<a href=”#” target=”_blank”></a>

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:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; table, th, td { border: 1px solid black; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table &gt; &lt;tr&gt; &lt;th&gt; Roll No. &lt;/th&gt; &lt;th&gt; Student Name &lt;/th&gt; &lt;th&gt; Subject Name &lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; 1 &lt;/td&gt; &lt;td&gt;Ram&lt;/td&gt; &lt;td&gt; Physics &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; 2 &lt;/td&gt; &lt;td&gt; Shyam &lt;/td&gt; &lt;td&gt; Math &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; 3 &lt;/td&gt; &lt;td&gt; Murli &lt;/td&gt; &lt;td&gt; Chemistry &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;

Output:

table

Q #8) Define Semantic elements in HTML.

Answer: Semantic elements are HTML elements that represent its meaning to the browser and developer about its contents.

For Examplep 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.

Q #9) Define attributes in HTML tag.

Answer: The HTML tag contains a field inside their tag which is called attributes of that tag.

For Example:

<img src=”#”> here in this tag src is img tag attributes.

<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:

&lt;input type=“text” id=“inputField”&gt; document.getElementById(“inputField”).attr(“type”, “password”);

Q #11) How can we comment in HTML?

Answer: Comments are used by developers to keep a track of the code functionality and also help the other developers in understanding the code functionalities easily.

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:

&lt;!-- This is one line comment ? &lt;!-- This is multiple         line of two or         more line --&gt;

Q #12) What are inline elements and block-level elements in HTML?

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.

Q #13) Can we change inline elements into block-level elements?

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;

Q #14) What are the different browsers that support HTML5?

Answer: All modern browsers support HTML5 elements except some old browsers. But fortunately, most of the browsers will take html5 elements as inline elements.

Q #15) What are <br> tags in HTML?

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.

Q #16) Explain the structure of the HTML webpage.

Answer: The common structure which all HTML pages follow are enlisted below:

(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.

&lt;!DOCTYPE html&gt;

(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.

&lt;html&gt;             &lt;!-- Rest of the html code will come inside it --&gt; &lt;/html&gt;

(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.

&lt;head&gt;            &lt;meta charset=&quot;UTF-8&quot;&gt;        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale = 1.0&quot;&gt;        &lt;title&gt;HTML Interview Questions&lt;/title&gt; &lt;/head&gt;

(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.

&lt;body&gt; &lt;h2&gt;Top HTML Interview Questions&lt;/h2&gt; &lt;p&gt;HTML stands for Hypertext Markup Language&lt;/p&gt; &lt;/body&gt;

Together the whole body will be:

&lt;! DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale = 1.0&quot;&gt; &lt;title&gt;HTML Interview Questions&lt;/title&gt; &lt;style type=&quot;text/css&quot;&gt; &lt;!-- CSS Code will be written into these --&gt; h2{ color: #1855b5; } p{ color: #3bd256; font-weight: 600; } &lt;/style&gt; &lt;script type=&quot;text/javascript&quot;&gt; &lt;!-- Javascript code will be written into these --&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Top HTML Interview Questions&lt;/h2&gt; &lt;p&gt;HTML stands for Hypertext Markup Language&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;

Output:

html-structure

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.

&lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale = 1.0&quot;&gt; &lt;meta name=&quot;description&quot; content=&quot;HTML interview questions&quot;&gt; &lt;meta name=&quot;author&quot; content=&quot;Author Name&quot;&gt; &lt;meta name=&quot;copyright&quot; content=&quot;All Rights Reserved&quot;&gt;

Q #18) Explain list elements in HTML.

Answer: Enlisted below are the list elements in HTML:

  • 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:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML Interview Questions Ordered List&lt;/title&gt; &lt;/head&gt; &lt;style&gt; h1{ color: red; } li{ color: #0070ff; } &lt;/style&gt; &lt;body&gt; &lt;h1&gt;Ordered List : &lt;/h1&gt; &lt;ol&gt; &lt;li&gt;HTML&lt;/li&gt; &lt;li&gt;CSS&lt;/li&gt; &lt;li&gt;Bootstrap&lt;/li&gt; &lt;li&gt;JavaScript&lt;/li&gt; &lt;/ol&gt; &lt;/body&gt; &lt;/html&gt;

Output:

ordered-list

Unordered List:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML Interview Questions Unordered List&lt;/title&gt; &lt;style&gt; h1{ color: red; } li{ color: #0070ff; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Unordered List : &lt;/h1&gt; &lt;ul&gt; &lt;li&gt;HTML&lt;/li&gt; &lt;li&gt;CSS&lt;/li&gt; &lt;li&gt;Bootstrap&lt;/li&gt; &lt;li&gt;JavaScript&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt;

Output:

unordered-list

Definition List:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML Interview Question Definition List&lt;/title&gt; &lt;style&gt; dt{ font-weight: 600; font-size: 25px; color: red; } dd{ font-weight: 500; font-size: 15px; color: #0070ff; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;dl&gt; &lt;dt&gt;&lt;strong&gt;HTML&lt;/strong&gt;&lt;/dt&gt; &lt;dd&gt;HTML stands for Hypertext Markup Language&lt;/dd&gt; &lt;dt&gt;&lt;bold&gt;CSS&lt;/bold&gt;&lt;/dt&gt; &lt;dd&gt;CSS stands for Cascading Style Sheets&lt;/dd&gt; &lt;/dl&gt; &lt;/body&gt; &lt;/html&gt;

Output:

definition-list

Q #19) Define iframe in HTML.

Answer: Iframe tag is written as <iframe>.

An iframe is used to display different document content inside the different document content in a rectangular region in the browser. When different document content is embedded into a current HTML content, then it is known as an inline iframe.

The src attribute contains the path to the document that occupies the inline iframe.

&lt;!DOCTYPE html&gt;            &lt;html&gt;                        &lt;head&gt;                                &lt;title&gt;HTML Interview Questions Iframes&lt;/title&gt;                       &lt;/head&gt;                       &lt;body&gt;                                   Iframe HTML Code                                  &lt;iframe src = &quot;demo_iframe.htm&quot; width = &quot;300&quot; height = &quot;300&quot;&gt;                                             Sorry your browser does not support inline frames.                                  &lt;/iframe&gt;                      &lt;/body&gt;          &lt;/html&gt;

Output:

iframe

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.

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML Interview Question Form tag&lt;/title&gt; &lt;style&gt; form { width: 200px; border: 2px solid blue; margin: 0 auto; padding: 60px 100px; } 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; padding: 15px 64px; margin-top: 20px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form &gt; &lt;p&gt;Name:&lt;/p&gt; &lt;input type = &quot;text&quot; name = &quot;user_name&quot; placeholder = &quot;Enter Name&quot;/&gt; &lt;br/&gt; &lt;br/&gt; &lt;p&gt;Email: &lt;/p&gt; &lt;input type = &quot;email&quot; name = &quot;user_email&quot; placeholder = &quot;Enter email&quot;/&gt; &lt;br/&gt; &lt;br/&gt; &lt;p&gt;Password: &lt;/p&gt; &lt;input type=&quot;password&quot; name = &quot;user_pwd&quot; placeholder = &quot;Enter Password&quot; /&gt; &lt;br/&gt; &lt;button&gt; Submit &lt;/button&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;

Output:

form

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.

Example using 6 types of headings in HTML:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; h1{ color: red; } h2{ color: blue; } h3{ color : green; } h4{ color: purple; } h5{ color: yellow; } h6{ color: orange; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Heading 1&lt;/h1&gt; &lt;h2&gt;Heading 2&lt;/h2&gt; &lt;h3&gt;Heading 3&lt;/h3&gt; &lt;h4&gt;Heading 4&lt;/h4&gt; &lt;h5&gt;Heading 5&lt;/h5&gt; &lt;h6&gt;Heading 6&lt;/h6&gt; &lt;/body&gt;

Output:

heading-tag

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.

Hyperlinks can be displayed in three ways:

  • Unvisited Link – These links are blue in color and underlined.
  • Visited Link – These links are purple in color and underlined.
  • Active Link – These links are red in color and underlined.

Q #23) Why do we use the required attribute in HTML?

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.

If the field is input then it will throw a default HTML error.

&lt;input type=&quot;email&quot; name = &quot;user_email&quot; required /&gt;

Q #24) How can we include Google maps on a website?

Answer: HTML code to include Google maps on our web page:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;HTML Interview Questions Google Map&lt;/h1&gt; &lt;div id=&quot;map&quot; style=&quot;width: 400px; height: 400px; background: yellow&quot;&gt; &lt;/div&gt; &lt;script&gt; function myMap() { var mapOptions = { center: new google.maps.LatLng(51.5, -0.12), zoom: 10 } var map = new google.maps.Map(document.getElementById(&quot;map&quot;), mapOptions); } &lt;/script&gt; &lt;script src= &quot;https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU&amp;callback=myMap&quot;&gt;&lt;/script&gt; &lt;/body&gt;&lt;/html&gt;

Output:

Output- google-map

Q #25) Differentiate between HTML and XHTML.

Answer: The differences between HTML and XHTML are:

  • 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.

Q #26) What are Web Workers?

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.

Q #27) What is the SVG element?

Answer: SVG is a followed XML format; it stands for Scalable Vector Graphics which is used to create vector graphics with the support for interactivity and animation.

SVG is resolution independent as it does not lose its quality when they are resized or zoomed.

Q #28) Explain about Canvas.

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:

&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;canvas id=&quot;myCanvas&quot; width=&quot;300&quot; height=&quot;200&quot; style=&quot;border:1px solid #d3d3d3; color: #c9cc18;&quot;&gt; Your browser does not support the HTML5 canvas tag.&lt;/canvas&gt; &lt;script&gt; var can = document.getElementById(&quot;myCanvas&quot;); var canvas = can.getContext(&quot;2d&quot;); canvas.font = &quot;20px Hind-sanserif&quot;; canvas.fillText(&quot;Canvas Example&quot;,30,60); &lt;/script&gt; &lt;/body&gt;

canvas

Q #29) Explain new form elements in HTML5.

Answer: The new form elements that were added into HTML5 are:

  • Datalist – It’s used as a list of options for input control.
  • Keygen – This tag defines a key-pair generator (Private/Public) field.
  • Output – It’s used to show the result of a calculation.

Q #30) What is Quirks mode in HTML5?

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.

Suggested reading =>> HTML Cheat Sheet

Hope, these interview questions would have enriched your knowledge of the HTML concept!!

We wish you all success!!

Was this helpful?

Submit Cancel Thanks for your feedback!

Recommended Reading

  • Interview Questions and Answers
  • ETL Testing Interview Questions and Answers
  • Top 30+ Popular Cucumber Interview Questions and Answers
  • Top 30 SAS Interview Questions and Answers
  • Top 30 Security Testing Interview Questions and Answers
  • 30+ Top Scrum Interview Questions and Answers [2024 LIST]
  • Top 30 DBMS Interview Questions and Answers
  • 30+ TOP Servlet Interview Questions and Answers [2024 LIST]

Từ khóa » Html And Css Interview Questions With Answers