
When preparing for frontend interviews, the holy trinity of web development—HTML, CSS, and JavaScript—remains the foundation of any technical assessment. Whether you are aiming for a junior role or a senior frontend engineer position, demonstrating a deep understanding of these core technologies is essential. In this guide, we will explore some of the most common and challenging interview questions to help you prepare.
The Core Triangle
Before diving into specific questions, it's crucial to understand how these three technologies interact to create a complete webpage experience.

- HTML provides the semantic structure and content.
- CSS dictates the presentation, layout, and visual styling.
- JavaScript introduces dynamic behavior, interactivity, and logic.
Let's look at some top interview questions for each category.
HTML Interview Questions
1. What are Semantic HTML elements and why are they important?
Semantic HTML means using HTML elements for their given purpose. Examples include <article>, <section>, <nav>, and <header> instead of using <div> for everything.
Why it's important:
- Accessibility: Screen readers rely on semantic tags to interpret the structure of a webpage.
- SEO: Search engines use semantic elements to better understand the content.
- Maintainability: Code is easier to read and maintain for developers.
2. Explain the difference between localStorage, sessionStorage, and cookies.
localStorage: Stores data with no expiration date. Data persists even after the browser is closed. Capacity is typically around 5-10MB.sessionStorage: Stores data for one session. Data is cleared when the page session ends (e.g., closing the tab).cookies: Small pieces of data sent with every HTTP request. Used primarily for server-side reading (like authentication). Capacity is limited to 4KB.
CSS Interview Questions
3. Explain the CSS Box Model.
The CSS box model is a box that wraps around every HTML element. It consists of:
- Content: The actual content of the box, where text and images appear.
- Padding: Clears an area around the content. It is transparent.
- Border: A border that goes around the padding and content.
- Margin: Clears an area outside the border. It is transparent.
Understanding box-sizing: border-box; is often a follow-up question, as it includes padding and borders in the element's total width and height.
4. What is the difference between Flexbox and CSS Grid?
- Flexbox is designed for one-dimensional layouts—either a row or a column. It excels at distributing space and aligning items within a single dimension.
- CSS Grid is a two-dimensional layout system. It handles both columns and rows simultaneously, making it ideal for overall page layout structuring.
JavaScript Interview Questions

5. What are Closures in JavaScript?
A closure is a feature where an inner function has access to the outer (enclosing) function's variables—a scope chain. It has three scope chains:
- Its own scope.
- Outer function's variables.
- Global variables.
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
const counter = makeCounter();
console.log(counter()); // 0
console.log(counter()); // 1
6. Explain Event Delegation.
Event delegation is a technique involving adding a single event listener to a parent element instead of adding multiple event listeners to individual child elements. It leverages the concept of event bubbling, where an event triggered on a child element bubbles up the DOM tree to its parent.
document.getElementById('parent-list').addEventListener('click', function(e) {
if(e.target && e.target.nodeName == 'LI') {
console.log('List item clicked: ', e.target.id);
}
});
7. What is the Event Loop?
The event loop is a mechanism that allows JavaScript to perform non-blocking operations despite being single-threaded. It constantly checks the call stack to see if it's empty, and if so, it looks at the callback queue. If there are pending callbacks, it pushes them to the call stack for execution.
Senior Frontend Deep Dive: Event Loop, Rendering Pipeline & Core Web Vitals
For mid-level and senior frontend engineering interviews, interviewers move quickly past basic HTML/CSS syntax into browser internals, JavaScript concurrency, and Core Web Vitals optimization:
| Browser Metric / Concept | What It Measures | Target Threshold | High-Impact Engineering Fix |
|---|---|---|---|
| LCP (Largest Contentful Paint) | Time until the largest above-the-fold hero image or heading renders. | ≤ 2.5 seconds | Use fetchpriority="high" on the hero <img>, inline critical CSS, and avoid client-side waterfalls before rendering text. |
| INP (Interaction to Next Paint) | Worst-case main-thread responsiveness across clicks, taps, and keystrokes. | ≤ 200 ms | Break up long tasks (>50ms) using scheduler.yield() or requestIdleCallback, and debounce expensive DOM re-renders. |
| CLS (Cumulative Layout Shift) | Visual stability—how much visible content jumps unexpectedly during load. | ≤ 0.1 | Always set explicit width and height (or CSS aspect-ratio) on images, embeds, and skeletons; use font-display: optional or size-adjusted fallbacks. |
8. Explain the exact execution order of Macrotasks, Microtasks, and requestAnimationFrame in the Browser Event Loop.
Answer: On each turn of the browser event loop:
- The engine pops one Macrotask from the task queue (e.g., initial script execution,
setTimeout,setInterval, or an I/O event) and runs it to completion until the call stack is empty. - Immediately after that macrotask finishes—and before yielding to the browser's rendering pipeline—the engine drains the entire Microtask Queue (
Promise.then/catch/finally,queueMicrotask,MutationObserver), including any new microtasks enqueued while draining. - If a screen repaint is due (~every 16.6ms at 60Hz), the browser executes
requestAnimationFramecallbacks, recalculates styles, computes Layout (Reflow), Paints layers, and Composites frames on the GPU.
9. What causes "Layout Thrashing" (Forced Synchronous Layout) and how do you eliminate it?
Answer: Layout thrashing occurs when JavaScript repeatedly interleaves DOM style writes and geometric layout reads inside a loop (for example, setting el.style.width = ... and immediately reading el.offsetHeight or el.getBoundingClientRect()). Reading a geometric property after a style mutation forces the browser to abort batching and synchronously recalculate layout on the main thread! To eliminate layout thrashing, batch all DOM reads first, compute new positions in memory, and apply all DOM mutations inside a single requestAnimationFrame callback—or animate GPU-composited properties (transform and opacity) that skip Layout and Paint entirely. Additionally, applying CSS content-visibility: auto on offscreen sections lets the browser skip layout and painting work for below-the-fold DOM subtrees until the user scrolls near them.
Conclusion
Mastering HTML, CSS, and JavaScript is non-negotiable for a frontend developer. Interviews often test not just your ability to write code, but your understanding of why things work the way they do under the hood.
If you're looking to put your knowledge to the test, totop.app offers guided mock tests and an AI Interview Agent designed specifically to help software engineers practice and perfect their interview skills. Keep coding, keep practicing, and you'll nail that interview!
Practice Senior React Engineer Questions Live with AI Mock Interviews
Turn any job description across Engineering, DevOps, Data, Marketing, Sales, Finance, or HR into a personalized test and live voice or text AI mock interview on totop.app, or test your speed right now in the 60-Second Senior React Engineer Blitz.
Play 60s Senior React Engineer Blitz (Free, No Login) | Start 14-Day Free Trial | Browse All Interview Guides