Loading content…
Loading content…
A comprehensive compile of junior, mid, and senior level HTML interview questions and answers covering semantic structures, storage strategies, and accessibility standards
<div>, <p>, <section>) start on a new line and stretch to take up the full available width of their parent container. They can contain block or inline elements.<span>, <a>, <strong>) do not start on a new line. They only take up as much width as their content wraps. They cannot contain block-level elements. In CSS, setting width and height properties has no effect on inline elements (unless display is changed to block or inline-block).<header>, <nav>, <main>, <article>, <aside>, <footer>) instead of generic structural wrappers like <div> and <span>.alt attribute on <img> tags required? What happens if it's left empty?alt attribute describes an image's content. It is required for accessibility:
alt text to visually impaired users.alt text in its place.alt="" tag. This tells screen readers to ignore the image entirely. Leaving the alt attribute out completely causes screen readers to read the image filename, which degrades the user experience.localStorage, sessionStorage, cookies, and IndexedDB.| Feature | Cookies | LocalStorage | SessionStorage | IndexedDB |
|---|---|---|---|---|
| Capacity | ~4KB | ~5MB - 10MB | ~5MB | > 250MB (Variable) |
| Expiry | Manually set | Never | Tab Close | Never |
| Server Access | Sent automatically | Client-only | Client-only | Client-only |
| Sync/Async | Synchronous | Synchronous | Synchronous | Asynchronous |
| Use Case | Auth sessions, settings | User preferences | Temp page state | Complex local data, offline apps |
async and defer attributes affect <script> tag loading?Parser: ████████████████████████████████
Default: [download & run] (blocks HTML)
Parser: ████████████ ███████████
Async: [download] [run] (blocks HTML during execution)
Parser: ████████████████████████████████
Defer: [download] [run] (executes after parsing completes)
async: Script downloads in the background. As soon as it finishes downloading, HTML parsing is paused while the script executes. Order of execution is not guaranteed (whichever downloads first runs first). Use for third-party scripts (e.g., Google Analytics).defer: Script downloads in the background. It executes only after the HTML parsing has fully finished. Order of execution is guaranteed (in the order they appear in the HTML). Best for application scripts.alt="", keyboard navigation must be possible without mouse emulation).role="dialog", aria-expanded="false"). ARIA alters the accessibility tree without changing the visual structure of the DOM.width and height properties on <img> and <video> tags so the browser allocates space before the asset downloads.translate) instead of animating position rules (top, left, margin) to prevent layout recalculations.role="dialog" and aria-modal="true". Link the heading to the modal container using aria-labelledby.element.focus().Tab / Shift+Tab) must be restricted to elements inside the modal. The user should not be able to tab out of the modal into background page elements.Escape must close the modal immediately.// Simple Focus Trap logic in Javascript:
const modal = document.getElementById("myModal");
const focusableElements = modal.querySelectorAll(
'button, [href], input, select, textarea, [tabindex="0"]'
);
const firstElement = focusableElements[0];
const lastElement = focusableElements[focusableElements.length - 1];
modal.addEventListener("keydown", (e) => {
if (e.key === "Tab") {
if (e.shiftKey) { // Shift + Tab (navigating backward)
if (document.activeElement === firstElement) {
lastElement.focus();
e.preventDefault();
}
} else { // Tab (navigating forward)
if (document.activeElement === lastElement) {
firstElement.focus();
e.preventDefault();
}
}
} else if (e.key === "Escape") {
closeModal(); // Custom function to close modal and restore focus
}
});
HTML Interview Cracking Checklist
async/defer) are key questions for web performance tuning.Marking it complete updates your roadmap progress percentage.