HTML Interview Questions

1. What is HTML?

HTML stands for HyperText Markup Language. It is the standard markup language used to structure and present content on the World Wide Web.


2. What is the DOCTYPE declaration in HTML?

The DOCTYPE declaration is an instruction that specifies the version of HTML or XML used in a web document. It helps web browsers to render the web page correctly.


3. What is the purpose of the `alt` attribute in the `<img>` tag?

The `alt` attribute is used to provide alternative text for an image if it cannot be displayed. It is important for accessibility and helps visually impaired users understand the content of the image.


4. What are semantic elements in HTML?

Semantic elements are HTML tags that convey meaning and structure to the web page content. Examples include `<header>`, `<nav>`, `<section>`, `<article>`, `<footer>`, and others.


5. What is the purpose of the `<form>` tag in HTML?

The `<form>` tag is used to create an HTML form for user input. It provides a container for form controls such as input fields, checkboxes, radio buttons, submit buttons, and more.


6. What is the difference between `<span>` and `<div>` in HTML?

The `<span>` and `<div>` tags are both container elements, but they have different default behaviors. `<span>` is an inline element used for small sections of text or inline styling, while `<div>` is a block-level element used for larger sections or to group other elements.


7. What is the purpose of the `href` attribute in the `<a>` tag?

The `href` attribute in the `<a>` tag is used to specify the URL or destination of a hyperlink. It determines the location the user is directed to when clicking on the link.


8. What is the purpose of the `<table>` tag in HTML?

The `<table>` tag is used to create a table or tabular data in HTML. It consists of rows and columns, with the content placed within the `<tr>`, `<td>`, and `<th>` tags for table rows, table data cells, and table headers, respectively.


9. What is the purpose of the `placeholder` attribute in an `<input>` tag?

The `placeholder` attribute is used to provide a hint or example text within an input field. It is displayed in the field until the user enters a value or interacts with the input.


10. What are the different types of lists in HTML?

HTML provides three types of lists: ordered lists (`<ol>`) that are numbered, unordered lists (`<ul>`) that are bulleted, and definition lists (`<dl>`) that consist of term-description pairs.


11. What is the purpose of the `<head>` tag in HTML?

The `<head>` tag is used to define the head section of an HTML document. It contains metadata, such as the document title, character encoding, CSS stylesheets, JavaScript scripts, and more.


12. What is the purpose of the `<label>` tag in HTML?

The `<label>` tag is used to define a label for an `<input>` element. It helps in associating a text description with its corresponding form field, making it more accessible and user-friendly.


13. What is the purpose of the `src` attribute in the `<script>` tag?

The `src` attribute is used to specify the source URL of an external JavaScript file. It allows you to include external scripts in your HTML document.


14. What is the purpose of the `colspan` attribute in the `<td>` tag?

The `colspan` attribute is used to specify the number of columns a table cell should span in a table row. It allows you to merge multiple cells horizontally.


15. What is the purpose of the `required` attribute in an `<input>` tag?

The `required` attribute is used to specify that an input field must be filled out before submitting a form. It helps in validating user input and preventing form submission without necessary information.


16. What is the purpose of the `<iframe>` tag in HTML?

The `<iframe>` tag is used to embed another HTML document or web page within the current document. It is commonly used to display external content or include interactive elements from other sources.


17. What is the purpose of the `disabled` attribute in an `<input>` tag?

The `disabled` attribute is used to disable an input field or form element. It prevents the user from interacting with or modifying the field's value.


18. What is the purpose of the `charset` attribute in the `<meta>` tag?

The `charset` attribute is used to specify the character encoding of an HTML document. It ensures that the browser interprets the text correctly and displays special characters, symbols, or non-English characters properly.


19. What are the different types of heading tags in HTML?

HTML provides six heading tags: `<h1>` to `<h6>`. `<h1>` is the highest level (most important) heading, while `<h6>` is the lowest level (least important) heading.


20. What is the purpose of the `target` attribute in the `<a>` tag?

The `target` attribute is used to specify where to open the linked document when clicking on an `<a>` tag. It can be set to `_blank` to open the link in a new browser tab or window.