HTML Interview Questions
HTML Interview Questions
Here is a list of the top 100 HTML interview questions along with their answers:
1. **What is HTML?**
- HTML stands for HyperText Markup Language. It is the standard language for creating web pages and
web applications.
- Tags are the basic building blocks of HTML, used to create elements on a web page. Tags are written
in angle brackets, such as `<html>`, `<head>`, `<body>`, etc.
- HTML is a standard markup language, while XHTML is a stricter version of HTML that follows XML
rules.
- Attributes provide additional information about HTML elements. They are always included in the
opening tag and usually come in name/value pairs like `name="value"`.
- A doctype declaration defines the HTML version to the browser. For example, `<!DOCTYPE html>` for
HTML5.
- HTML5 introduces new elements like `<article>`, `<section>`, `<nav>`, `<header>`, `<footer>`,
`<canvas>`, `<audio>`, `<video>`, etc., along with new attributes and APIs.
7. **What is the purpose of the `<head>` section in HTML?**
- The `<head>` section contains meta-information about the HTML document, such as its title, links to
CSS, scripts, and meta tags.
- Block-level elements start on a new line and take up the full width available (e.g., `<div>`, `<p>`,
`<h1>`), while inline elements do not start on a new line and only take up as much width as necessary
(e.g., `<span>`, `<a>`, `<img>`).
- Use the `<a>` tag with the `href` attribute. Example: `<a href="https://www.example.com">Click
here</a>`.
- Use the `<img>` tag with the `src` attribute. Example: `<img src="image.jpg" alt="Description">`.
- The `<meta>` tag provides metadata about the HTML document, such as character set, author,
description, and viewport settings.
- Use the `<table>` tag along with `<tr>` (table row), `<th>` (table header), and `<td>` (table data) tags.
14. **What is the purpose of the `<form>` tag?**
- The `<form>` tag is used to create a form for user input, which can be submitted to a server for
processing.
- Semantic HTML elements clearly describe their meaning in a human- and machine-readable way.
Examples include `<article>`, `<section>`, `<aside>`, and `<header>`.
- Use the `<video>` tag with the `src` attribute or nested `<source>` tags. Example: `<video
src="video.mp4" controls></video>`.
- The `alt` attribute provides alternative text for an image if it cannot be displayed, aiding accessibility
and SEO.
- Use `<ul>` for an unordered list, `<ol>` for an ordered list, and `<li>` for list items.
- The `<iframe>` tag is used to embed another HTML document within the current document.
- `<b>` and `<i>` are used for visual styling (bold and italic), while `<strong>` and `<em>` are used to
give semantic importance (strong emphasis and emphasis).
- The `data-*` attribute is used to store custom data private to the page or application.
- The `<template>` tag holds client-side content that will not be rendered when the page loads but can
be used later via JavaScript.
- Web workers are scripts that run in the background, separate from the main browser thread,
allowing for background processing.
- Use the `Cache Manifest` to specify resources the browser should cache and make available offline.
28. **What is the purpose of the `<canvas>` element in HTML5?**
- The `<canvas>` element is used to draw graphics on a web page via JavaScript.
- Use the `<link rel="icon" href="favicon.ico" type="image/x-icon">` tag in the `<head>` section.
- The `<picture>` element allows you to define multiple sources for an image, providing flexibility for
responsive designs.
- The `required` attribute specifies that an input field must be filled out before submitting the form.
- The `placeholder` attribute specifies a short hint that describes the expected value of an input field.
36. **How do you create a radio button in HTML?**
37. **What is the use of the `<fieldset>` and `<legend>` tags in a form?**
- The `<fieldset>` tag groups related elements in a form, and the `<legend>` tag provides a caption for
the `<fieldset>`.
- The `action` attribute specifies where to send the form data when the form is submitted.
- The Drag and Drop API allows elements to be dragged and dropped within and between web pages.
- The Web Storage API provides a way to store data in the browser, including `localStorage` for
persistent storage and `sessionStorage` for temporary storage.
43. **What is the WebSocket API?**
- The WebSocket API provides a way to open a two-way interactive communication session between
the user's browser and a server.
- The History API allows manipulation of the browser's session history, including methods like
`pushState`, `replaceState`, and `popstate` events.
- `localStorage` stores data with no expiration date, while `sessionStorage` stores data only for the
duration of the page session.
- Use the `navigator.geolocation` object to get the current geographical location of the user.