CSS interview questions, html css interview questions, and html and css interview questions appear in junior frontend, UI engineer, and full-stack screening rounds before JavaScript framework depth. Interviewers expect you to explain why a rule wins (cascade and specificity), choose flexbox vs grid with reasons, debug overflow and sticky bugs, and describe 2026-era CSS such as container queries, @layer, and :has(). This guide covers HTML structure and CSS layout together because most hiring loops treat them as one fundamentals block.
Below are 45 questions with elaborate answers; technical sections include a strong answer sample you can say aloud. Pair with front end developer interviews for JavaScript, React, and Core Web Vitals breadth, TypeScript interview questions when roles type components, React interview questions for component styling patterns, Selenium interview questions for locator and DOM timing context, and full stack developer interviews when UI meets API design.
!important.
Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; Chromium 138 for layout behavior checks.
Interview context and how to prepare
What do CSS and HTML interviews actually test?
CSS and HTML interviews test whether you can structure pages correctly and predict layout behavior—not whether you memorized every property name.
| Layer | What interviewers probe |
|---|---|
| HTML | Semantics, forms, accessibility, document structure |
| Cascade | Specificity, inheritance, @layer, source order |
| Box model | box-sizing, margin collapse, overflow |
| Layout | Flexbox, grid, positioning, centering |
| Responsive | Media queries, container queries, fluid units |
| Modern CSS | :has(), logical properties, subgrid |
| Maintainability | BEM, avoiding specificity wars, critical CSS |
| Role | Emphasis |
|---|---|
| Junior | Box model, flex centering, semantic tags |
| Mid-level | Grid layouts, responsive nav, debugging cascade |
| Senior | Architecture, performance, design-system trade-offs |
Live exercises often ask you to debug specificity, choose flex vs grid, and build a responsive card layout.
Why are HTML and CSS tested together?
HTML provides meaning and structure; CSS provides presentation. Interviewers combine them because broken UI often starts with wrong markup.
| Concern | HTML role | CSS role |
|---|---|---|
| Accessibility | <button>, <label>, headings |
Focus styles, visible focus rings |
| SEO | <h1>–<h6>, landmarks |
None (content structure) |
| Layout | Wrapper elements | display, flex, grid |
| Forms | input types, name |
Spacing, error states |
| Responsive images | <picture>, srcset |
max-width: 100% |
A page with div soup may look fine until keyboard navigation, screen readers, or mobile reflow fail.
What is a typical HTML/CSS interview loop?
| Round | Duration | Focus |
|---|---|---|
| Screening | 30 min | Portfolio, stack, CSS comfort |
| HTML/CSS fundamentals | 45 min | Semantics, box model, flex/grid |
| Live layout exercise | 45–60 min | Navbar, card grid, centering |
| JavaScript / framework | 45–60 min | Often React—see dedicated guides |
| System / senior | 45 min | Design systems, performance, a11y |
Written rounds often start with the box model, specificity, and centering; live rounds add responsive navigation and sticky header debugging.
What is a realistic 3–5 week HTML/CSS prep plan?
| Week | Focus | Output |
|---|---|---|
| 1 | Semantic HTML, forms, a11y basics | Rebuild a landing page structure |
| 2 | Box model, specificity, cascade, @layer |
Debug a conflicting stylesheet |
| 3 | Flexbox deep dive | Nav bar + centered hero |
| 4 | Grid + responsive patterns | Card gallery with auto-fit |
| 5 | Modern CSS + mock interview | Container queries, :has(), timed layout |
Build one portfolio layout you can whiteboard: explain every display choice aloud.
How do junior and senior CSS expectations differ?
| Topic | Junior | Senior |
|---|---|---|
| Layout | Flex centering, basic grid | Composed flex+grid systems |
| Cascade | Class vs ID specificity | @layer, design tokens, isolation |
| Responsive | Media queries | Container queries + fluid type |
| Performance | max-width: 100% on images |
Critical CSS, layout thrashing |
| Architecture | Single stylesheet | BEM, CSS modules, utility trade-offs |
| Debugging | Toggle rules in DevTools | Stacking contexts, containing blocks |
Seniors are judged on maintainability and cross-browser judgment, not trick properties.
HTML fundamentals
What is semantic HTML and why does it matter?
Semantic HTML uses elements that describe meaning, not only appearance.
| Instead of | Prefer | Why |
|---|---|---|
<div class="button"> |
<button> |
Keyboard, focus, disabled state |
<div class="nav"> |
<nav> |
Landmark for assistive tech |
<b> for headings |
<h1>–<h6> |
Document outline, SEO |
<span onclick> |
<button> or <a href> |
Accessible activation |
Benefits interviewers want to hear:
- Accessibility — browsers expose roles and keyboard behavior
- SEO — crawlers weight heading hierarchy
- Maintainability — less custom ARIA to remember
- Default styling — user-agent styles as baseline
A strong answer is:
Semantic HTML gives me correct behavior before CSS—buttons focus, headings outline, forms associate labels—and ARIA should enhance, not replace, the right tag.
Explain DOCTYPE and basic document structure.
<!DOCTYPE html> tells the browser to use standards mode (HTML5). Without it, older quirks mode can change box model and layout math.
Minimal valid skeleton:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page title</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>...</header>
<main>...</main>
<footer>...</footer>
</body>
</html>Key points:
langhelps screen readers pick pronunciationcharset=utf-8avoids mojibakeviewportmeta is required for mobile-responsive CSS- One
<main>per page for the primary content landmark
A strong answer is:
DOCTYPE enables standards mode; I always set charset, viewport, and lang so CSS layout and accessibility behave predictably on mobile.
Block vs inline vs inline-block elements?
| Display (default) | Layout behavior | Examples |
|---|---|---|
| Block | New line; width fills container | div, p, h1, section |
| Inline | Flows in text line; width from content | span, a, strong |
| Inline-block | Inline flow but accepts width/height | img, button, input |
CSS can override with display: block | inline | inline-block | flex | grid | none.
Common interview trap: applying width and height to a default inline span has no effect until you change display.
A strong answer is:
Block elements stack vertically and accept full width; inline elements flow with text; inline-block is the bridge when I need sizing on an inline flow.
HTML forms — what should you know for interviews?
Forms connect user input to servers and accessibility.
| Element | Purpose |
|---|---|
<form action method> |
Submission target and HTTP verb |
<label for="id"> |
Clickable label tied to control |
| `<input type="email | password |
<textarea> |
Multi-line text |
<select> / <option> |
Dropdown choices |
required, pattern, min, max |
Client-side validation attributes |
Interviewers check whether you use native input types (better mobile keyboards) and labels, not placeholder-only forms.
<label for="email">Email</label>
<input id="email" name="email" type="email" required autocomplete="email">A strong answer is:
I pair every input with a label, pick the right type for validation and mobile UX, and style error states in CSS without removing native focus rings.
Accessibility basics — ARIA vs semantic HTML?
WCAG principles: Perceivable, Operable, Understandable, Robust.
| Practice | Detail |
|---|---|
| Semantic first | <button>, <nav>, <main> before ARIA roles |
| Keyboard | All interactive elements reachable via Tab |
| Focus visible | Never outline: none without replacement |
| Color contrast | Text meets 4.5:1 (normal) or 3:1 (large) |
| Alt text | Meaningful alt on informative images |
| ARIA when needed | aria-expanded, aria-live for dynamic widgets |
Rule of thumb: no ARIA is better than wrong ARIA when a native element exists.
A strong answer is:
I use semantic HTML for default a11y, add ARIA only for custom widgets, and keep focus styles visible—accessibility is part of HTML/CSS fundamentals, not a bonus round.
Important `<head>` tags for layout and SEO?
| Tag | Role |
|---|---|
<meta charset="utf-8"> |
Character encoding |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
Mobile scaling |
<title> |
Tab title, search snippet |
<meta name="description"> |
Search summary |
<link rel="stylesheet"> |
CSS (render-blocking by default) |
<link rel="preload" as="font" crossorigin> |
Critical font loading |
<link rel="icon"> |
Favicon |
Missing viewport meta is a classic reason media queries never seem to work on phones—the page renders at desktop width then scales down.
A strong answer is:
Viewport meta unlocks responsive CSS on mobile; I preload only critical fonts and defer non-essential stylesheets when performance matters.
CSS fundamentals — cascade and selectors
Explain the CSS cascade — what decides the winning rule?
When multiple rules target the same element, the browser resolves in order:
- Origin and importance — user
!important, author!important, author normal, user normal, browser defaults - Cascade layers —
@layerorder (if used) - Specificity — selector weight
- Source order — later rule wins if specificity ties
@layer reset, base, components, utilities;
@layer components {
.card { padding: 1rem; }
}
@layer utilities {
.p-0 { padding: 0; } /* wins over .card if layers ordered this way */
}Understanding cascade lets you fix bugs without random class renames.
A strong answer is:
I trace conflicts in order: importance, layers, specificity, then source order—layers let teams ship utilities without specificity wars.
How is CSS specificity calculated?
Specificity is often written as (inline, IDs, classes/attributes/pseudo-classes, elements/pseudo-elements).
| Selector | Specificity (simplified) |
|---|---|
p |
0,0,0,1 |
.btn |
0,0,1,0 |
#nav .btn |
0,1,1,0 |
style="color:red" |
1,0,0,0 |
!important |
Beats non-important regardless (avoid in answers as first resort) |
:not(.x) adds specificity of its argument; :where(.x) contributes zero specificity.
Interviewers ask you to compare:
div.card { } /* 0,0,1,1 */
.card.primary { } /* 0,0,2,0 — wins */A strong answer is:
I count IDs, classes, and elements—
:where()for resets with zero weight—and avoid ID selectors in components because they are painful to override.
What inherits in CSS and what does not?
Inherited properties flow to children: color, font-family, line-height, visibility (usually), custom properties.
Non-inherited (each element defaults): margin, padding, border, width, height, background, display.
body {
font-family: system-ui, sans-serif;
color: #1e293b;
}
/* All text inherits font and color unless overridden */Resets vs normalize:
- Reset — strips margins/padding globally
- Normalize — preserves useful defaults, fixes browser bugs
Modern projects often use a small reset plus box-sizing: border-box globally.
A strong answer is:
Typography and color inherit; box model does not—I set font on
bodyand reset margins deliberately rather than fighting user-agent defaults per component.
Important CSS selector types?
| Selector | Example | Use |
|---|---|---|
| Type | p, h1 |
Low specificity baselines |
| Class | .card |
Components (preferred) |
| ID | #header |
Avoid for styling (high specificity) |
| Attribute | [type="email"] |
Form styling |
| Descendant | .nav a |
Any nested link |
| Child | .nav > a |
Direct children only |
| Adjacent sibling | h2 + p |
First paragraph after heading |
| Pseudo-class | :hover, :focus-visible, :nth-child(2) |
State and position |
| Pseudo-element | ::before, ::after, ::placeholder |
Generated decoration |
:focus-visible (not bare :focus on mouse click) is the 2026 accessibility-friendly pattern.
A strong answer is:
I style with classes, use pseudo-classes for interaction states, and prefer
:focus-visibleso keyboard users see focus without mouse click rings everywhere.
CSS units — px, rem, em, %, vh, fr?
| Unit | Meaning | Typical use |
|---|---|---|
| px | Absolute pixels | Borders, shadows, fine layout |
| rem | Root font-size multiple |
Spacing, typography (accessible scaling) |
| em | Parent font-size multiple |
Component-relative padding |
| % | Percent of parent | Width in fluid layouts |
| vh/vw | Viewport height/width | Full-screen sections (watch mobile URL bar) |
| fr | Grid fraction | grid-template-columns: 1fr 2fr |
| ch | Character width | max-width: 65ch for readable line length |
Interview tip: set html { font-size: 100%; } and use rem for scalable design systems.
A strong answer is:
rem for global scale tied to user font settings, fr for grid tracks, and ch for readable line length—I avoid vh-only full-height heroes on mobile without
dvhfallback.
CSS custom properties (variables)?
Custom properties are live, inheritable values declared with --name:
:root {
--color-primary: #264de4;
--space-md: 1rem;
}
.button {
background: var(--color-primary);
padding: var(--space-md);
}
.card {
--color-primary: #e44d26; /* override in subtree */
}Unlike Sass variables, they cascade and work in the browser at runtime—ideal for theming and dark mode.
@media (prefers-color-scheme: dark) {
:root {
--color-bg: #0f172a;
--color-text: #f8fafc;
}
}A strong answer is:
Custom properties cascade for theming—I define tokens on
:rootand override in scopes like.darkorprefers-color-schemewithout rebuilding CSS.
`:is()`, `:where()`, and `:has()` — why do interviewers ask?
Modern functional pseudo-classes reduce selector bloat:
/* :is() — specificity = most specific argument */
:is(h1, h2, h3) { line-height: 1.2; }
/* :where() — zero specificity */
:where(ul, ol) { margin: 0; padding: 0; list-style: none; }
/* :has() — parent selector (supported in major browsers) */
.card:has(img) { padding-top: 0; }
.form-group:has(:invalid) { border-color: red; }:has() enables parent styling based on children—previously impossible without JavaScript.
A strong answer is:
:where()for zero-specificity resets,:has()for parent-aware styling like invalid form groups—I'm careful with:has()performance on huge DOMs.
Box model, display, and positioning
Explain the CSS box model and box-sizing.
Every element is a rectangle with:
content → padding → border → margin
box-sizing |
Width includes |
|---|---|
content-box (default) |
Content only—padding and border add to total size |
border-box |
Content + padding + border inside stated width |
*, *::before, *::after {
box-sizing: border-box;
}
.box {
width: 200px;
padding: 16px;
border: 2px solid #333;
/* border-box: total width stays 200px */
}The box model—content, padding, border, and margin—is one of the first topics most interviewers ask about.
A strong answer is:
border-box makes width math predictable—padding and border stay inside the declared width, which is why global border-box resets are standard.
What is margin collapse?
Vertical margins between block-level siblings (or parent/first-child) can collapse into one margin equal to the larger value—not the sum.
h1 { margin-bottom: 24px; }
p { margin-top: 16px; }
/* Gap between h1 and p is 24px, not 40px */Prevention techniques:
paddingorborderon parent (creates block formatting context edge)display: flow-rooton parent- Flex/grid container (margins do not collapse with children the same way)
Interviewers use this to test whether you understand unexpected whitespace bugs.
A strong answer is:
Vertical margins collapse between blocks—I use padding, flex/grid, or flow-root on parents when I need spacing that does not collapse unexpectedly.
Key `display` values and when to use them?
| Value | Effect |
|---|---|
block |
Stack, full width available |
inline |
Text flow, no width/height |
inline-block |
Inline flow with box model |
none |
Removed from layout (not same as visibility: hidden) |
flex |
One-dimensional flex formatting context |
grid |
Two-dimensional grid formatting context |
flow-root |
BFC root—contains floats, stops margin collapse |
visibility: hidden keeps layout space; display: none removes the element from layout entirely.
A strong answer is:
display creates formatting contexts—flex and grid for layout, flow-root to contain floats, none to remove from accessibility tree when paired with care.
CSS positioning — static, relative, absolute, fixed, sticky?
| Value | Behavior |
|---|---|
static |
Default document flow |
relative |
Offset from normal position; creates positioning context for children |
absolute |
Removed from flow; positioned vs nearest positioned ancestor |
fixed |
vs viewport (often) |
sticky |
Hybrid: relative until scroll threshold, then fixed within container |
.dropdown {
position: relative;
}
.menu {
position: absolute;
top: 100%;
left: 0;
}Sticky fails when any ancestor has overflow: hidden—a common live-debug question.
A strong answer is:
absolute positions against the nearest non-static ancestor; sticky needs room to stick and breaks under overflow:hidden parents—I verify the containing block chain in DevTools.
z-index and stacking contexts?
z-index only compares elements in the same stacking context. A new context is created by:
position+z-index(notstatic)opacityless than 1transform,filter,isolation: isolate- Flex/grid items with
z-index
.modal-backdrop { z-index: 100; }
.modal { z-index: 101; }
/* Both need same parent context or modal may sit under unrelated UI */Interview fix for "my dropdown is behind the header": parent created a lower stacking context.
A strong answer is:
z-index is not global—I find which ancestor creates a stacking context and raise that context, not random 9999 values on children.
Flexbox
Flex container properties you must know?
.nav {
display: flex;
flex-direction: row; /* row | column */
flex-wrap: wrap; /* nowrap | wrap */
justify-content: space-between; /* main axis */
align-items: center; /* cross axis */
align-content: center; /* multi-line cross axis */
gap: 1rem;
}| Property | Axis |
|---|---|
justify-content |
Main axis distribution |
align-items |
Cross axis alignment (single line) |
align-content |
Cross axis when wrapped multiple lines |
gap |
Space between items (preferred over margin hacks) |
Main axis follows flex-direction; default is row (horizontal).
A strong answer is:
justify-content distributes on the main axis, align-items on the cross axis—I set flex-direction first because it defines which axis is which.
Flex item properties — flex-grow, flex-shrink, flex-basis?
.sidebar { flex: 0 0 250px; } /* grow shrink basis */
.content { flex: 1 1 auto; } /* grow to fill */Shorthand flex: <grow> <shrink> <basis>:
| Part | Meaning |
|---|---|
flex-grow |
Share of free space (0 = do not grow) |
flex-shrink |
Shrink ratio when overflow |
flex-basis |
Initial size before grow/shrink |
flex: 1 often means flex: 1 1 0% in modern browsers—check design system docs.
A strong answer is:
flex: 1 on content areas lets them absorb free space; fixed sidebars use flex: 0 0 250px so they do not shrink unexpectedly.
How do you center an element with flexbox?
.center-both {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; /* or parent with defined height */
}Other methods interviewers expect:
| Method | CSS idea |
|---|---|
| Grid | place-items: center on parent |
| Absolute + transform | top/left 50% + translate(-50%, -50%) |
| Margin auto | Block with width: margin: 0 auto (horizontal only) |
Flex/grid are preferred in 2026 over table-cell hacks.
A strong answer is:
For one-off centering I use flex with justify and align center on a parent with defined height; for page regions I might use grid place-items center.
flex-wrap and gap — practical use?
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}flex-wrap: wrap— items move to next line instead of overflowinggap— consistent spacing without negative margin tricks on containers
order can reorder visually but does not change tab order—accessibility caution in interviews.
A strong answer is:
wrap plus gap builds responsive chip rows without nth-child margin hacks—I avoid order for focus order unless I mirror it in the DOM.
Why is `min-width: 0` a common flex/grid fix?
Flex and grid items default to min-width: auto, meaning they will not shrink below content size—long text or wide children cause overflow.
.flex-child {
flex: 1;
min-width: 0; /* allow shrinking; pair with overflow hidden or text-overflow */
}Flex children default to min-width: auto, which blocks shrinking—common cause of truncated text in sidebars and horizontal scroll bugs.
A strong answer is:
min-width: 0 lets flex children shrink below content intrinsic width—essential for ellipsis sidebars and responsive dashboards.
CSS Grid
Flexbox vs CSS Grid — when do you use each?
| Use Flexbox | Use Grid |
|---|---|
| One-dimensional (row or column) | Two-dimensional (rows and columns) |
| Content-driven sizing | Layout-driven tracks |
| Nav bars, toolbars, card internals | Page layouts, card galleries |
| Alignment along one axis | Explicit areas and tracks |
They compose:
.page {
display: grid;
grid-template-columns: 240px 1fr;
min-height: 100vh;
}
.header nav {
display: flex;
justify-content: space-between;
}Interviewers often ask when you would pick flex versus grid for a given layout—state the axis and content flow, not just property names.
A strong answer is:
Grid for page skeleton and two-axis regions; flex inside components for alignment—I do not force everything into one system.
grid-template-columns, fr, and minmax?
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
}
.responsive-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
}| Function | Role |
|---|---|
fr |
Fraction of free space after fixed tracks |
minmax(min, max) |
Clamp track size |
repeat(n, track) |
Avoid manual column lists |
auto-fit collapses empty tracks; auto-fill keeps empty columns—subtle interview difference.
A strong answer is:
auto-fit minmax makes responsive card grids without media queries—tracks grow and wrap based on container width.
grid-template-areas for readable layouts?
.layout {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 200px 1fr;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
header { grid-area: header; }
aside { grid-area: sidebar; }
main { grid-area: main; }
footer { grid-area: footer; }Named areas make responsive reflow readable—change the string in one media query.
A strong answer is:
grid-template-areas documents layout intent in one place—I rewrite the area map at breakpoints instead of renumbering columns.
grid-column, grid-row, and implicit grid?
Explicit placement:
.featured {
grid-column: 1 / -1; /* span full width */
}
.span-two {
grid-column: span 2;
}If items exceed defined tracks, the implicit grid creates extra rows/columns with grid-auto-rows defaults.
subgrid (nested grid inherits parent tracks) matters for design-system alignment in 2026 senior questions.
A strong answer is:
I use span and line numbers for featured cards; subgrid when nested components must align to the parent column tracks.
What is CSS subgrid?
subgrid lets a nested grid align to parent grid lines:
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
}Before subgrid, card internals misaligned across rows when titles varied in height.
Browser support is broad in 2026 Chromium, Firefox, and Safari—mention progressive enhancement.
A strong answer is:
subgrid syncs nested rows to the parent grid so card actions align across uneven content—I use it in card galleries and form sections.
Responsive design and modern CSS
Media queries and mobile-first CSS?
/* Mobile-first: base styles for small screens */
.nav { flex-direction: column; }
@media (min-width: 768px) {
.nav { flex-direction: row; }
}Common breakpoints are content-driven, not device lists—adjust when layout breaks.
| Query | Use |
|---|---|
min-width |
Mobile-first escalation |
max-width |
Desktop-first reduction |
prefers-reduced-motion |
Accessibility |
prefers-color-scheme |
Dark mode |
Pair with responsive images: srcset, sizes, <picture>.
A strong answer is:
I start mobile-first with min-width queries at points where the design breaks, not arbitrary iPhone widths.
Container queries vs media queries?
Media queries react to viewport; container queries react to parent container size:
.card-container {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 400px) {
.card { display: grid; grid-template-columns: 120px 1fr; }
}Use when a reusable component must adapt inside sidebar vs main column—viewport width is misleading.
A strong answer is:
Container queries style components by their slot width—media queries for page-level changes; container queries for reusable cards and widgets.
Fluid typography with clamp()?
h1 {
font-size: clamp(1.5rem, 2vw + 1rem, 2.5rem);
}clamp(min, preferred, max) scales smoothly without dozens of breakpoints.
| Technique | Role |
|---|---|
clamp() |
Fluid size with bounds |
min() / max() |
Cap or floor values |
rem base |
Respects user font settings |
A strong answer is:
clamp gives fluid headings with accessible bounds—I avoid px-only hero text that ignores user zoom settings.
Logical properties — margin-inline, padding-block?
Logical properties map to writing direction instead of physical left/right:
| Physical | Logical |
|---|---|
margin-left |
margin-inline-start |
width |
inline-size |
height |
block-size |
top / bottom |
block-start / block-end |
Benefits for RTL languages and internationalized apps—interviewers test awareness, not memorization of every name.
.card {
padding-inline: 1rem;
padding-block: 0.75rem;
border-inline-start: 3px solid var(--accent);
}A strong answer is:
Logical properties keep spacing correct in RTL—I use margin-inline and padding-block instead of left/right in new code.
Overflow, images, and responsive media?
img, video {
max-width: 100%;
height: auto;
display: block;
}
.scroll-panel {
overflow: auto;
max-height: 400px;
}| Issue | Fix |
|---|---|
| Image overflows container | max-width: 100% |
| Layout shift (CLS) | width/height attributes or aspect-ratio |
| Cropped hero | object-fit: cover with fixed aspect-ratio box |
.hero-img {
aspect-ratio: 16 / 9;
object-fit: cover;
width: 100%;
}A strong answer is:
max-width 100% on media plus aspect-ratio on heroes reduces overflow and CLS—I set dimensions in HTML when possible.
Architecture, performance, and animations
BEM and CSS architecture basics?
BEM — Block, Element, Modifier:
.card { }
.card__title { }
.card__title--featured { }Goals:
- Predictable class names — no deep nesting in selectors
- Flat specificity — usually one class per rule
- Reusable blocks —
.cardworks across pages
Alternatives: CSS Modules, utility-first (Tailwind), CSS-in-JS—interviewers want trade-off awareness, not framework wars.
| Approach | Pros | Cons |
|---|---|---|
| BEM | Explicit, low specificity | Verbose class strings |
| Utilities | Fast prototyping | HTML noise |
| CSS Modules | Scoped by build | Build step |
A strong answer is:
BEM keeps specificity flat and namespaced—I pick CSS Modules or utilities when the team already standardized on them.
Specificity wars and when `!important` is acceptable?
Specificity wars happen when teams stack IDs, deep selectors, and overrides.
Prevention:
- Prefer single-class component rules
- Use
@layerfor utilities vs components - Avoid ID selectors for styling
- Document token changes instead of one-off overrides
!important is acceptable rarely: utility overrides, third-party widget hacks, print stylesheets—not daily layout fixes.
A strong answer is:
I fix specificity at the source with layers and class discipline—!important is a last resort for third-party CSS I cannot edit.
CSS performance — what matters in interviews?
| Topic | Guidance |
|---|---|
| Selector cost | Modern engines are fast; avoid huge unused CSS bundles |
| Critical CSS | Inline above-the-fold styles; defer rest |
| Layout thrashing | Batch DOM reads/writes in JS (see front-end guide) |
| Animations | Prefer transform and opacity for compositor |
| will-change | Sparingly—hints GPU layer, costs memory |
Heavy box-shadow and filter on animated elements can hurt INP—tie to front end performance when asked.
A strong answer is:
I ship smaller CSS, animate transform/opacity, and avoid layout-triggering properties in loops—performance is measurable, not theoretical.
Transitions vs animations?
.button {
transition: background-color 0.2s ease, transform 0.2s ease;
}
.button:hover {
transform: translateY(-2px);
}
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
.modal {
animation: fade-in 0.3s ease-out;
}| Feature | Use |
|---|---|
transition |
Simple A → B on property change |
@keyframes |
Multi-step or looping motion |
prefers-reduced-motion |
Disable or shorten motion |
Respect accessibility—do not rely on motion alone for critical feedback.
A strong answer is:
transitions for hover/focus states; keyframes for entrance effects—I gate motion with prefers-reduced-motion for accessibility.
Live scenarios and debugging
Scenario: Styles not applying — how do you debug?
Checklist interviewers want spoken aloud:
- DevTools Styles panel — which rule wins and why (strikethrough losers)
- Specificity — compare competing selectors
- Cascade layers —
@layerorder - Typo — wrong class name or missing stylesheet link
- Source order — duplicate imports
- Inherited vs direct — property may not inherit
- Shorthand override —
backgroundresettingbackground-color - Parent overflow — clipping or sticky failure
Stack Overflow threads on join/compare specificity mirror this systematic cascade read.
A strong answer is:
I read DevTools computed styles, trace the winning rule through specificity and layers, and fix the selector—not sprinkle !important until I understand the conflict.
Final prep checklist
What should you rehearse before HTML/CSS interviews?
Checklist:
- Semantic HTML — landmarks, forms, headings
- Box model — border-box, margin collapse
- Specificity — calculate winners; know
@layer - Flexbox — centering, wrap, gap, min-width: 0
- Grid — auto-fit minmax, areas, subgrid awareness
- Positioning — absolute containing block, sticky pitfalls
- z-index — stacking contexts
- Responsive — mobile-first, container queries
- Modern —
:has(), logical properties,clamp() - One live layout — navbar + card grid timed
- Front end interviews for JS and performance
- TypeScript interviews if stack uses TS
- React interviews for component styling next step
A strong answer is:
I time-box one full page build weekly—semantic HTML, grid page, flex components—and explain every cascade conflict I fixed without !important.
Pattern cheat sheet (quick reference)
| Task | HTML/CSS approach |
|---|---|
| Page regions | CSS Grid + grid-template-areas |
| Nav / toolbar | Flexbox + gap |
| Responsive cards | repeat(auto-fit, minmax(280px, 1fr)) |
| Center child | Flex justify + align center |
| Flat specificity | BEM or @layer |
| Theme tokens | Custom properties on :root |
| Parent-aware style | :has() |
| Component-responsive | Container queries |
| Fluid headings | clamp() |
| Truncate in flex | min-width: 0 + text-overflow: ellipsis |
| Debug conflicts | DevTools → specificity → layers |
References
On-site prep
- Front end developer interviews
- TypeScript interview questions
- React interview questions and answers
- React JS interview questions for experienced developers
- Angular developer interview questions
- Selenium interview questions
- Full stack developer interviews
- Interview Questions category
Summary
CSS and HTML interviews test cascade mechanics, layout choices (flex vs grid), and responsive debugging—not property lists from memory. Rebuild a responsive layout, calculate specificity on paper, and compare your answers to each section. Pair with front end developer interviews, TypeScript, and React when the role continues into components.

