HTML & CSS Interview Prep — Common Questions and Patterns
The HTML and CSS questions that come up in real front-end interviews, answered at senior-engineer depth.
Quick answer
Front-end interviews return to a few fundamentals: semantic HTML, the box model, specificity and the cascade, Flexbox versus Grid, centring, responsive design, stacking contexts and accessibility. Explaining why a solution works matters as much as the code.
- Know three ways to centre an element and when each fits.
- Explain specificity order and how box-sizing changes widths.
- Talk through accessibility: semantics, focus and contrast.
/* Flexbox */
.a { display: flex; justify-content: center; align-items: center; }
/* Grid */
.b { display: grid; place-items: center; }
/* Positioning */
.c > .child { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }Everything From This Track, Interview-Ready
This lesson is different from the other 41 — instead of teaching one new topic in depth, it pulls together the questions, patterns, and hands-on challenges from across the entire curriculum into the format an actual front-end interview uses: real questions, answered completely, organized by theme, plus the "build this" coding challenges that come up constantly in real interview loops. If a question below references something unfamiliar, the module it was originally covered in is named — this is meant to be a review and synthesis, not a first introduction.
Structure, Meaning, and Whether Every User Can Actually Use What You Built
The Fundamentals Every Front-End Interview Assumes You Know Cold
Layout Decision-Making — The Question Every Interview Eventually Asks
Building for Every Screen, and Keeping It Fast
Four Classic Problems, Worked Through Completely
Beyond conceptual questions, most front-end interviews include at least one live "build this" or "fix this" exercise. These four are among the most commonly seen — not because the exact prompts repeat verbatim, but because the underlying techniques (centering, grid-based composition, flex-based page shells, box-model debugging) generalize to a huge fraction of what actually gets asked.
1. Center a div — three different ways, and their trade-offs
A deceptively simple prompt that is really testing whether you understand several layout systems well enough to choose deliberately between them, not just whether you can produce centered content.
.parent {
display: flex;
justify-content: center; /* centers on the main axis */
align-items: center; /* centers on the cross axis */
height: 100vh;
}
/* Works for one or many children, unknown child dimensions, and adapts
instantly if the child's size changes. The default choice in most
real projects for this exact problem. */.parent {
display: grid;
place-items: center; /* shorthand for align-items + justify-items, both centered */
height: 100vh;
}
/* Marginally more concise than the Flexbox version for a SINGLE
centered child. Less natural if you also need to distribute
several children in a row alongside the centering. */.parent { position: relative; height: 100vh; }
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Useful specifically when the parent's layout mode can't change
(it needs to stay a normal block flow for other reasons), or when
centering an element ON TOP of other content rather than among it.
Requires knowing this specific top/left + transform combination —
margin: auto alone only centers horizontally in a block context. */The trade-off worth stating out loud in an interview: Flexbox and Grid are the modern defaults because they don't remove the element from normal flow and adapt automatically to content size changes; the absolute-positioning approach is reached for specifically when the element needs to be centered independent of its siblings' layout, such as a modal overlay centered on top of unrelated page content.
2. Build a responsive card grid from scratch
A staple layout exercise — a grid of cards that reflows its column count based on available width, without a fixed breakpoint list to maintain.
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 24px;
}
/* auto-fit tells Grid to fit as many 240px+ columns as the container
allows, and 1fr lets each column stretch to fill any remaining
space evenly. As the viewport shrinks, columns drop one at a time
automatically — the same rule handles a phone, a tablet, and an
ultrawide monitor with zero explicit breakpoints. */.card {
background: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,.1);
padding: 16px;
display: flex;
flex-direction: column;
gap: 8px;
}A strong follow-up an interviewer often asks: what happens with exactly one card in the grid? With auto-fit, that single card stretches to fill the full row width (since 1fr claims all remaining space). If a single card should instead stay at its minimum size rather than stretching, swapping auto-fit for auto-fill changes that behavior — worth knowing the distinction exists, even if auto-fit is the more commonly desired behavior for a genuine card grid.
3. Fix this broken sticky footer
A footer that should sit at the bottom of the viewport on short pages, but scrolls up and leaves a gap, or overlaps content, is one of the most commonly seen "fix this" prompts.
body { margin: 0; }
.footer { position: absolute; bottom: 0; width: 100%; }
/* On a page with little content, the footer sits at the bottom of the
VIEWPORT initially, but position: absolute takes it out of normal
flow entirely — it doesn't push against the actual page content, so
as soon as any content overlaps that same vertical space, the
footer sits ON TOP of it instead of below it. */html, body { height: 100%; margin: 0; }
.page {
display: flex;
flex-direction: column;
min-height: 100%;
}
.main-content { flex: 1; } /* grows to fill any remaining space */
.footer { /* no special positioning needed at all */ }
/* <body><div class="page"><header>...</header>
<main class="main-content">...</main>
<footer class="footer">...</footer>
</div></body> */The mechanism: flex: 1 on the main content area means it grows to consume any leftover vertical space in the flex column, pushing the footer down to the bottom of the viewport on short pages — but because the footer is still in normal flow (not position: absolute), it is naturally pushed further down by real content on longer pages instead of overlapping it. This is the same core idea covered in the Flexbox in Practice module, worth being able to reproduce from memory.
4. Explain and fix this box-sizing bug
A short, deliberately broken snippet — a very common warm-up exercise meant to check that box model fundamentals are genuinely internalized, not just memorized as a definition.
.column {
width: 33.33%;
padding: 0 16px;
float: left;
box-sizing: content-box; /* the default, made explicit here */
}
/* Three columns at exactly 33.33% width EACH, plus 32px of padding
added on top of every one of them (16px left + 16px right), pushes
the total rendered width past 100% of the container — the third
column has nowhere left to go and wraps onto a new row. */.column {
width: 33.33%;
padding: 0 16px;
float: left;
box-sizing: border-box; /* padding is now included WITHIN the 33.33% */
}
/* Now each column's rendered width, padding included, is exactly
33.33% of the container — three of them sum to exactly 100%,
fitting on a single row as intended. */Worth naming explicitly in an interview: this exact bug is precisely why * { box-sizing: border-box; } is applied so broadly as a near-universal reset in real projects — it eliminates this entire category of "the math doesn't add up to 100%" layout bug by default, rather than requiring every component author to remember it individually.
A Front-End Interview Loop at a Media Startup in Portland
A candidate is asked to live-code a responsive card grid for an article listing page, starting from a bare HTML skeleton. They reach for CSS Grid's repeat(auto-fit, minmax(240px, 1fr)) pattern immediately, get a working reflowing grid in under two minutes, and the interviewer moves on to the actual point of the exercise: "the design calls for the cards to be centered as a group when there are fewer than three of them, instead of stretching to fill the row. How would you handle that?"
The candidate talks through two real options out loud before writing code: constraining the grid's max-width and centering the grid container itself with margin: 0 auto (works, but doesn't truly center individual cards when there are exactly one or two), versus switching the grid's justify-content to center so existing columns cluster in the middle rather than stretching to fill unused space. They implement the second option, then proactively test it by removing cards down to a single one in DevTools to confirm the behavior holds at every count — without being asked to.
What the interviewer was actually evaluating
The hiring debrief centered on two things: that the candidate reasoned about a genuinely subtle Grid behavior (how auto-fit and justify-content interact when column count is low) rather than guessing and iterating blindly, and that they tested an edge case unprompted. As the panel put it afterward: "we weren't testing whether they knew the exact syntax on day one — most of the syntax questions get looked up constantly on real teams anyway. We were testing whether they could reason clearly about layout behavior and verify their own work." This is exactly why every Q&A in this module has consistently paired the mechanism with the reasoning behind it, not just a memorized final answer.
Four Misconceptions About How These Interviews Are Actually Graded
🎯 Key Takeaways
- ✓Interviews reward reasoning out loud — why Flexbox versus Grid, why a bug is happening, what edge case needs verifying — at least as much as a single correct final answer.
- ✓A small set of recurring patterns (Flexbox/Grid centering, responsive grids via auto-fit, the Flexbox sticky-footer pattern, box-sizing debugging) covers a large fraction of real front-end layout interview questions.
- ✓The conceptual fundamentals that come up constantly — the box model, specificity and the cascade, stacking contexts, the difference between semantic and non-semantic markup — are exactly the ones this curriculum flagged individually across earlier lessons, because they are also genuinely common real production bugs, not just interview trivia.
- ✓Semantic HTML and basic accessibility are treated as baseline front-end competence, not a specialty track — expect them to surface even in interviews not explicitly framed around accessibility.
- ✓Testing your own solution against edge cases (very few grid items, a very narrow viewport, long content) unprompted is consistently rated positively — it mirrors real engineering practice, not just interview performance.
🎉 Track Complete — All 42 Modules
You've completed the full HTML & CSS track — foundations to advanced.
From your first <!DOCTYPE html> through semantic structure, forms, the box model, the cascade, Flexbox and Grid, responsive design, modern CSS, and now interview readiness — that is the complete arc of what a working front-end engineer actually needs. Revisit any module as a reference whenever a real project calls for it; that is exactly what this track is for, not just a one-time read-through.
Quick check
What does place-items: center do in a grid container?
HELP US IMPROVE
How was this lesson?
Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.
Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.
