THN Interview Prep

CSS Architecture & Modern Layouts

CSS architecture is the work of keeping presentation predictable at product scale. The goal is not one favorite methodology; it is a system where teams can ship layouts, themes, responsive behavior, and states without specificity wars or runtime surprises.

Core details

TopicWhat to knowFailure mode
Cascadeorigin, importance, layers, specificity, source order“Why did this style win?” becomes archaeology
LayoutFlexbox for one axis, Grid for two axes, subgrid where supportednested wrappers and brittle media queries
Container queriescomponent responds to its container, not viewportcard works on page A but breaks in sidebar
Custom propertiesruntime tokens and inheritanceaccidental global token mutation
ArchitectureCSS Modules, utility CSS, CSS-in-JS, plain CSS layersteam mixes all patterns without ownership
Performancecritical CSS, runtime injection, selector invalidationstyling blocks render or causes hot-path churn

Cascade layers: @layer gives an explicit precedence model that can be easier than escalating specificity.

@layer reset, tokens, base, components, utilities;

@layer components {
  .button {
    color: var(--color-fg);
  }
}

@layer utilities {
  .text-danger {
    color: var(--color-danger);
  }
}

Flexbox vs Grid: Flexbox distributes items along one primary axis. Grid defines rows and columns together. Use Grid for page and card matrices; use Flexbox for toolbars, inline controls, and content that wraps naturally.

Container queries: declare a query container with container or container-type, then adapt descendants based on the container’s size.

.profile-card {
  container: card / inline-size;
}

@container card (min-width: 36rem) {
  .profile-card__body {
    display: grid;
    grid-template-columns: 12rem 1fr;
  }
}

Understanding

CSS problems usually come from unclear ownership. A design token says what values exist. A component stylesheet says how a component uses those values. A utility says how to make a narrow override. When those layers blur, teams fix bugs by adding stronger selectors and eventually no one trusts the system.

Modern CSS moved logic into the platform: container queries, cascade layers, custom properties, :has, logical properties, media queries for user preferences, and layout primitives reduce the need for JavaScript measurement. The senior move is to use these features where they simplify ownership, with progressive enhancement where support or product risk requires it.

Styling architecture also affects rendering. Runtime CSS-in-JS can delay or invalidate style work if it injects rules during render. Utility CSS can keep output bounded but may bloat markup and require strict tooling. CSS Modules give local scoping but still need token and layering discipline.

Practical choices

NeedGood defaultWatch for
Design system componentsCSS Modules or layered CSS with tokensleaking implementation classes as public API
High-volume product surfacesstatic extraction / build-time CSSruntime injection and hydration mismatch
Rapid app UIutility-first with strict tokensunreadable markup and one-off values
ThemingCSS custom propertiescontrast and inheritance regressions
Reusable cardscontainer queriesmissing containment context

Use logical properties (margin-inline, padding-block) when supporting internationalized layouts. Use prefers-reduced-motion and color-scheme/media preferences as product states, not afterthoughts.

Senior understanding

ProbeStrong answer
“Tailwind vs CSS Modules?”Compare governance, token discipline, bundle/runtime cost, and team workflow
“Why not CSS-in-JS?”Distinguish runtime injection from compiled extraction; discuss SSR and critical CSS
“Specificity bug?”Use cascade layers and ownership boundaries before stronger selectors
“Responsive component?”Prefer container queries when layout depends on parent context

Failure modes

  • Using !important as an architecture tool.
  • Styling by DOM depth instead of component contract.
  • Writing viewport media queries for components that appear in many containers.
  • Mutating global CSS variables from one widget and affecting unrelated UI.
  • Adding animation without reduced-motion and layout stability checks.

Diagram

Loading diagram…

See also

Spotted something unclear or wrong on this page?

On this page