Interview Questions
Interview Questions
1. What is HTML?
Answer: HTML stands for HyperText Markup Language. It is the standard language used to create and
structure content on the web. HTML provides the basic framework of a web page using a system of
tags and attributes. These tags tell the browser how to display text, images, links, and other media.
HTML is not a programming language; it's a markup language that defines the structure and layout of
web content.
Key features:
Platform-independent
Answer: Semantic HTML elements clearly describe their meaning in a human- and machine-readable
way. For example:
Use inline-block when you want inline elements that behave like blocks (e.g., buttons in a row).
Answer: data-* attributes are custom attributes used to store extra information on HTML elements
that don’t affect the layout or display. They are useful for storing data for JavaScript use.
Example:
<button data-user-id="123">Click</button>
You can access it via JavaScript:
Use cases:
Answer: The alt attribute provides alternative text for an image if it fails to load or for users with
screen readers.
Benefits:
Improves accessibility
Aids SEO
Example:
<img src="logo.png" alt="Company Logo">
Attribute Id Class
Shared styling/behavior across multiple
Usage Unique element identifier
elements
Selector #id .class
Can only be used once per
Reuse Can be used multiple times
page
Answer: Void elements are HTML tags that do not have a closing tag because they do not contain any
content.
Examples:
<img> – image
<meta> – metadata
Correct usage:
<img src="logo.png" alt="Company Logo">
In HTML5, it's fine to omit the slash (<br> instead of <br />), unlike XHTML.
Answer: The <meta> tag provides metadata about the HTML document. It is placed inside the <head>
section and is used for:
Character encoding
Page description
Examples:
<meta charset="UTF-8">
<meta name="description" content="Web dev tutorial">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Tag Purpose
<script> Embeds JavaScript or links to an external JS file
<noscript> Displays fallback content if JavaScript is disabled in the browser
<style> Embeds internal CSS in the HTML document
Examples:
<script src="main.js"></script>
<noscript>Your browser does not support JavaScript.</noscript>
<style>body { background: #f0f0f0; }</style>
HTML5 introduced new input types that improve user experience and provide better semantic
meaning and built-in validation.
Input
Description Example
Type
text Single-line text input <input type="text">
Requires a valid email
email <input type="email">
format
Numeric input with <input type="number"
number
min/max options min="1">
Slider control for numeric <input type="range" min="1"
range
input max="5">
date Calendar date selector <input type="date">
time Time picker <input type="time">
color Color picker <input type="color">
tel Telephone number input <input type="tel">
url Must be a valid URL format <input type="url">
search Styled for search fields <input type="search">
file File upload <input type="file">
Example:
HTML provides client-side form validation using built-in input types and attributes:
Required fields: required
Example:
🔷 Advanced Topics
1. What are data-* Attributes?
Used to store custom data on HTML elements. These do not affect layout or behavior by themselves
but are useful for scripts.
Example:
<div data-user-id="1234" data-role="admin">User</div>
Access in JS:
element.dataset.userId; // "1234"
element.dataset.role; // "admin"
2. localStorage vs sessionStorage
Example:
localStorage.setItem('theme', 'dark');
sessionStorage.setItem('page', 'dashboard');
These elements improve SEO and assist screen readers in understanding layout structure.
Example:
<iframe src="https://example.com" width="500" height="300"></iframe>
Uses:
Security Note: Use sandbox and allow attributes to restrict iframe permissions.
Example:
<label for="email">Email</label>
<input type="email" id="email" aria-required="true">
Screen readers use these cues to interpret and narrate the page.