Top 20 HTML Interview Questions & Answers — Codeymaze

CodeyMaze
3 min readJul 24, 2024

--

HTML stands for Hyper Text Markup Language. It is a standard markup language for creating web pages. It describes the structure of a Web page. HTML is an integral part of website development.

In this article we will list down some important HTML interview questions for your frontend interview preparation.

1. What do you understand by HTML elements?

HTML elements are fundamental elements used to structure and define content on web page for ex. headings, paragraphs, links etc.

2. What does <!DOCTYPE HTML> do?

DOCTYPE stands for Defining Document Type and Validation Mode. It Specifies the HTML or XHTML version used in the document. Also Identifies parsing method and algorithm for the web browser, affecting consistency.

The <!DOCTYPE> declaration is placed at the very top of the HTML file, even before the <html> tag begins.

3. What are non-semantic elements?

Unlike semantic elements, non-semantic elements are those elements that don’t have any meaning and does not tell anything about the content they contain. Example of non-semantic elements are <div>, <span>

4. What is the difference between id and class attributes?

Id attribute is unique to an element and class can be applied to multiple elements.

5. What do you understand by inline and block elements?

Inline elements do not start on new line and only take as much width as necessary. These elements are small elements which can be nested inside block elements. Some examples of inline elements are <a>, <span>, <strong>, <em>, <br>, <input>

Block level elements start on a new line and take full width available. These elements can be used to contain inline elements. Some examples of block elements are <div>, <p>, <ul>, <li>, <h1> to <h6>

6. What is the difference between display:none and visibility:hidden?

Visibility:hidden hides the element but it still takes up space. Display:none hides the element and does not takes up space.

7. What is the HTML tag that is used to display the data in tabular form?

HTML Table tag is used to display the data in tabular form in rows and columns. We can use <tr> inside <table> to create rows and <td> to create cells inside rows.

8. What are semantic HTML tags in HTML?

Semantic HTML tags provide both structure and meaning to web content. They allow crawlers, browsers, and even assistive technologies to understand content better and present it more effectively. This approach improves accessibility and search engine optimization, making pages easier to maintain and understand.

Some of the common semantic HTML tags includes :

  • <P> : A paragraph
  • <a> : for links
  • <img> : for images
  • <H1> to H6> : for headings
  • <li> : list items

9. What is the difference between localStorage and sessionStorage?

localStorage: localStorage is a way to store data on the client’s computer. It allows the saving of key/value pairs in a web browser and it stores data with no expiration date. localStorage can only be accessed via JavaScript, and HTML5. However, the user has the ability to clear the browser data/cache to erase all localStorage data.

sessionStorage: stores data only for a session, meaning that the data is stored until the browser (or tab) is closed.

10. What is the difference between the <div> and <span> tags?

<div> is a block level element used for grouping and structuring large content. <span> is an inline element used to wrap small pieces of content within its parent element.

11. What are data-attributes in HTML, and how are they used?

Data attributes in HTML5, often referred to as data-* attributes, help embed custom data within HTML elements.

Originally published at https://codeymaze.com on July 24, 2024.

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet