Below is a clean, professional, and beginner-friendly list of HTML interview questions with answers — ideal for students, freshers, and working professionals.
HTML (HyperText Markup Language) is the standard markup language used to create web pages. It structures the content using elements like headings, paragraphs, images, links, and forms.
Tags are the building blocks of HTML. They define how content is structured.
<p>This is a paragraph.</p>
Attributes provide extra information about an element.
<img src="image.jpg" alt="Sample Image">
The DOCTYPE tells the browser which HTML version the document uses.
HTML5 DOCTYPE:
<!DOCTYPE html>
Semantic elements describe the meaning of content.
Examples:
<header>, <footer>, <section>, <article>, <nav>, <main>.
| Element | Type | Use Case |
|---|---|---|
| <div> | Block-level | Layout structure |
| <span> | Inline | Styling text inside lines |
Used for metadata such as keywords, description, viewport settings etc.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Contains metadata and resources like CSS, scripts, title etc. It doesn’t display content.
HTML5 is the latest version of HTML that introduces:
Used to draw graphics, animations, and games using JavaScript.
| Feature | SVG | Canvas |
|---|---|---|
| Type | Vector-based | Pixel-based |
| Best For | Icons, shapes | Games, charts |
| Scalable | Yes | No (loses quality) |
Using the <script> tag:
<script src="app.js"></script>
Three ways:
Embeds external content like maps, ads, or websites.
Used to collect user input like name, email, and password.
text, email, password, number, date, file, checkbox, radio.
Displays a hint inside input fields.
| Method | Use Case |
|---|---|
| GET | Fetch data, shows parameters in URL |
| POST | Secure submission, does not show data in URL |
<video controls src="movie.mp4"></video>
Used to embed audio files.
It allows storing data on the client browser:
More secure and larger capacity than cookies.
Background scripts that run without blocking the main UI thread.
Gets the user’s real-time location (with permission).
Allows the server to send real-time updates to the browser.
Creates a two-way real-time communication between client and server.
Elements that do not have closing tags:<img>, <br>, <hr>, <input>, <meta>, <link>.
| HTML | XHTML |
|---|---|
| Not strict | Very strict |
| Case-insensitive | Lowercase only |
| Attributes optional | Attributes mandatory |
ARIA = Accessible Rich Internet Applications.
Helps screen readers and disabled users understand web content.
Loads images only when they appear in the viewport:
<img src="photo.jpg" loading="lazy">