HTML Interview Questions 1-5 (Semantics, HTML5, Elements)
Hello! While this course focuses heavily on Python and backend logic, a Full Stack Developer must respect the frontend. HTML is the skeleton of the web. Without it, your Python API has no face.
In this lesson, we are going back to basics, but with a professional twist. We aren't just learning tags; we are learning why specific tags matter for accessibility (a11y), Search Engine Optimization (SEO), and browser performance. These are the questions interviewers ask to filter out developers who rely too heavily on frameworks without understanding the core standards.
1. What is semantic HTML?
Semantic HTML means using HTML elements that clearly describe their meaning to both the browser and the developer, rather than just how they look.
Analogy: Moving Houses
Imagine moving into a new house. You have 50 boxes.
- Non-Semantic: Every box is labeled "Stuff". You have to open them to know what's inside.
- Semantic: Boxes are labeled "Kitchen", "Bedroom", "Books". You know exactly where they go without looking inside.
In code, this means avoiding "div soup" (using <div> for everything).
- Non-Semantic elements:
<div>,<span>(Tells us nothing about its content). - Semantic elements:
<form>,<table>,<article>,<header>,<footer>(Clearly defines content).
Why is this an interview favorite?
It shows you care about Accessibility. Screen readers use semantic tags to navigate. If you use a <div> for a button, a blind user might not know it is clickable.
<div class="header">
<div class="nav">...</div>
</div>
<div class="main-content">
<div class="article">...</div>
</div>
<header>
<nav>...</nav>
</header>
<main>
<article>...</article>
</main>2. Explain HTML5 new features.
HTML5 was a massive leap forward. It turned HTML from a document structure language into a full-blown application platform. Before HTML5, we needed Flash for videos and heavy cookies for local storage.
Here are the key features you should mention:
| Feature Area | Description |
|---|---|
| New Semantics | Tags like <nav>, <section>, <aside>, <figure>. |
| Multimedia | Native support for audio and video via <audio> and <video>. No plugins needed. |
| Graphics | <canvas> for JS drawing and standard SVG support. |
| Storage | localStorage and sessionStorage to replace large cookies. |
| APIs | Geolocation, Drag and Drop, and Web Workers. |
Here is an example of the native video player, which was impossible in plain HTML4.
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>Sample Output:
A fully functional video player appears in the browser with play/pause controls, volume, and timeline.
3. Difference between block and inline elements.
This question tests your understanding of the Box Model and document flow. Browsers render elements in two primary ways by default.
1. Block-level Elements
These elements act like "paragraphs".
- They always start on a new line.
- They take up the full width available (stretching to the left and right).
- Examples: <div>, <h1> through <h6>, <p>, <form>, <header>.
2. Inline Elements
These elements act like "words" in a sentence.
- They do not start on a new line.
- They only take up as much width as necessary.
- Crucial limitation: You cannot set width or height on standard inline elements.
- Examples: <span>, <a>, <img>, <strong>.
Technical Note: With CSS, you can change this behavior using display: inline-block or display: flex, but the interviewer is asking about the default behavior of HTML tags.
<div style="background: red;">I am a block</div>
<div style="background: blue;">I am another block</div>
<span style="background: yellow;">I am inline</span>
<span style="background: green;">Me too!</span>4. What are HTML attributes?
HTML elements are the nouns of a page (paragraph, image, table). Attributes are the adjectives. They provide additional information about elements.
Attributes are always specified in the start tag and usually come in name/value pairs like name="value".
- Core Attributes:
id(unique identifier),class(category identifier),style(inline CSS),title(tooltip). - Specific Attributes:
href(for links),src(for images/scripts),alt(for accessibility). - Boolean Attributes: These don't need a value. Their presence implies "true". Examples:
disabled,checked,required.
<a href="https://stackscholar.com" target="_blank">Visit Us</a>
<img src="logo.png" alt="Company Logo" width="500" height="600">
<input type="text" disabled>5. What are HTML5 forms?
Before HTML5, building forms was tedious. You needed complex JavaScript just to check if an email address contained an "@" symbol or to pick a calendar date. HTML5 introduced intelligent form controls that handle validation and UI natively.
New Input Types:
Instead of just type="text", we now have semantic inputs that mobile browsers love (e.g., opening a number pad for "tel").
type="email": Validates email format automatically.type="date": Opens a native date picker.type="number": Restricts input to numbers, often with spinner controls.type="range": Creates a slider control.type="color": Opens a native color picker.
New Attributes:
placeholder: Hint text inside the field.required: Prevents submission if empty.pattern: Allows regex validation directly in HTML.autofocus: Automatically focuses the input on page load.
<form>
<label for="email">Email:</label>
<input type="email" id="email" required placeholder="you@example.com">
<label for="age">Age:</label>
<input type="number" id="age" min="18" max="99">
<label for="birthday">Birthday:</label>
<input type="date" id="birthday">
<button type="submit">Register</button>
</form>Sample Output behavior:
If you try to submit this form with "hello" in the email field, the browser itself will pop up a message saying: "Please include an '@' in the email address."No JavaScript required!