HTML/CSS Interview Questions

12 HTML/CSS interview questions with worked answers, complexity notes, and runnable code you can edit in the browser — ordered easy to hard so you build up steadily. Free, no signup. Open any question for the full answer.

What HTML and CSS interviews are really testing

The questions look like trivia — center a div, explain specificity, when do you use flexbox versus grid — but the interviewer is reading for one thing: do you reason about layout from the rules, or do you guess and nudge until it looks right? Everything below traces back to a small set of models. The box model decides how width, padding, and border add up. Normal flow decides where boxes go before you touch position or flex. The cascade and specificity decide which rule wins when two conflict. Stacking contexts decide what sits on top of what. Learn those four and most “how do I…” questions answer themselves.

Layout is the deep end. Flexbox is one-dimensional — content laid along a single axis, sized by its contents; grid is two-dimensional — you define the tracks and place items into them. Reach for flex when the layout follows the content, and grid when the content follows the layout. Centering, the interview cliché, is really a question about which containing block you are centering within and which axis you mean.

Responsiveness rewards restraint: fluid units, sensible breakpoints, and min(), max(), and clamp() beat a wall of media queries. Accessibility is not a separate topic — semantic markup, visible focus, and sufficient contrast are the difference between a demo and a shippable component. The questions here move from those foundations up through the ones that trip seniors: z-index bugs that are really stacking-context bugs, collapsing margins, and the layout thrash that quietly costs you frames.

Easy

Medium

Hard

Other topics

Browser · JavaScript · TypeScript · React · System Design · Accessibility · Web Performance · Testing · Networking/Security · DSA

← Search all 265 questions