skip to content

CSS

4 roadmaps240 questionsupdated

CSS is the layer that turns markup into a working layout, and interviewers probe it hard because most of the language is invisible rules — the cascade, formatting contexts, sizing algorithms — that only surface when something breaks. This tree covers the language itself: how a declaration wins, how boxes size and flow, how flex and grid lay things out, and how you keep a large stylesheet from collapsing under its own weight.

on this pageshow

guide

overview

~1 min

CSS reads as a flat list of declarations, but what reaches the screen is decided by rules that never appear in the source: which declaration wins, how a box works out its size, which ancestor an element is positioned against, what paints over what. Interviewers probe CSS because those rules are invisible until something breaks. Naming the rule behind a bug — the parent has no definite height, that ancestor opened a stacking context — shows you debug from a model, not by trial and error. The hub follows the questions a style answers on its way to the screen. [Selectors and specificity](/topics/fe-css-selectors-specificity) decides which declaration applies at all. [Box model and flow](/topics/fe-css-box-model) sizes each element and stacks boxes in normal flow. [Flexbox](/topics/fe-css-flexbox) and [Grid](/topics/fe-css-grid) are the two layout modes a container can switch its children into, and [positioning and stacking](/topics/fe-css-positioning-stacking) covers boxes that leave flow and the order in which things paint. [Responsive design](/topics/fe-css-responsive) makes one stylesheet hold across viewports and containers, [custom properties and animations](/topics/fe-css-custom-props-animations) add runtime values and motion, and [CSS architecture](/topics/fe-css-architecture) is about keeping all of it maintainable when many people write it. Junior rounds check vocabulary: specificity, `box-sizing`, the `flex` shorthand, grid lines. Middle and senior rounds hand you a misbehaving layout and expect the rule that explains it — margin collapsing, the automatic minimum size of flex items, stacking contexts, containing blocks — plus a view on newer tools such as cascade layers and container queries. At the top of the range the conversation turns to architecture: how a team keeps selector weight flat and styles local across hundreds of components. Start with the cascade and the box model; flex and grid make sense once you know how one box decides its size.

primer

### The cascade decides; specificity is one step of it Every property on every element ends with one value, and the cascade picks it. Origin and importance, cascade layers, specificity and source order are consulted in a fixed sequence, and each later step matters only when the earlier ones tie. Most "my style isn't applying" answers turn on *which step* decided, not on how much weight to add. Inheritance is a separate mechanism: for inherited properties it fills in a value when nothing in the cascade targets the element. ### A size is the output of an algorithm `width: 200px` is an input, not a result. What renders depends on `box-sizing`, on whether the containing block's size is definite, on the element's intrinsic content sizes, and on the layout mode of its parent. Every percentage resolves against *something*; when that something is not definite, the percentage quietly falls back. ### The parent's layout mode rules the child `display` on a parent chooses the formatting context its children live in — block flow, flex or grid — and the same child property can mean different things in each. Vertical margins collapse in block flow but not between flex or grid items; auto margins absorb free space in flex and grid; `z-index` works on flex and grid items without positioning them. Name the context first. ### Flex sizes from the items, grid from the container Flexbox starts with each item's base size, then hands out leftover space, or takes it back, along one axis. Grid starts with tracks the container defines and places items into them, lining things up across rows and columns at once. A good "flex or grid" answer says which way sizing should flow — content outward or layout inward — rather than reciting "grid for pages, flex for components". ### Leaving flow needs a reference point A positioned box is offset against a containing block, and which ancestor provides it depends on the `position` value and on properties such as `transform` that create one without announcing it. Painting is organised into stacking contexts: nested groups that `z-index` compares only within, never across. Together they explain the classic overlay bugs — the clipped dropdown, the modal pinned to a card, the enormous `z-index` that still loses. ### Responsive means reasoning from content Viewport breakpoints are one tool among several. Relative units, `clamp()`, intrinsic grid tracks and container queries all help a component adapt without knowing the page width. Interviewers listen for breakpoints placed where the content breaks, not at device widths. ### Values and motion happen at runtime Custom properties exist in the browser: they cascade, inherit and resolve per element, which makes them the theming mechanism — and means a bad value surfaces late, at computed-value time, rather than at parse time. Animation is runtime too: what you animate decides how much work each frame costs, and users can ask the system for less motion. ### At scale, CSS fails through weight and names Large stylesheets decay through override wars and colliding global class names. BEM, utility classes, cascade layers, CSS Modules and `@scope` are different answers to the same two questions: how overrides stay predictable, and how a change stays local.

Cascade
The algorithm that chooses one value per property per element from every competing declaration, comparing origin and importance, layer, specificity and source order in turn.
Specificity
A selector's weight, scored in three columns: IDs; classes, attributes and pseudo-classes; element types and pseudo-elements. It is consulted only after origin, importance and layer tie.
Cascade layer
A named bucket of rules declared with @layer. For normal declarations, layer order is settled before specificity, so a later layer's simple selector beats an earlier layer's complex one.
Inheritance
The mechanism by which some properties, mostly text-related, take their value from the parent element when no declaration sets them on the element itself.
Box model
The four nested areas of every box: content, padding, border and margin. box-sizing decides whether width and height measure the content area or reach out to the border.
Containing block
The rectangle a box's percentages and insets resolve against. For static and relative boxes it is usually the parent's content box; absolute and fixed boxes look elsewhere.
Block formatting context
An independent region of block layout. It contains its floats, keeps outside floats from overlapping it, and stops margins collapsing across its edge.
Margin collapsing
The rule by which adjoining vertical margins of block boxes in normal flow merge into a single margin instead of adding together.
Intrinsic size
A size derived from content rather than declared, such as min-content and max-content, or the natural dimensions and ratio of an image.
Flex basis
An item's starting main size before free space is shared out or removed. flex-grow and flex-shrink adjust from this value, not from zero.
fr unit
A grid track size meaning one share of the space left after fixed tracks, gaps and content minimums are accounted for.
Stacking context
A group of elements painted together as one layer. z-index orders elements only inside the same stacking context, never across two of them.
Container query
An @container rule that applies styles according to the size of an ancestor declared as a query container, rather than the viewport.
Custom property
A property whose name starts with two dashes. It cascades and inherits like any other and is read into values with var().

Follow one rule from stylesheet to screen. The browser matches selectors against the document, and the cascade picks one declared value per property per element; inheritance and initial values fill the gaps. Values are then computed — relative units resolved, `var()` substituted. Layout comes next: each parent's `display` selects the algorithm — block flow, flex or grid — and that algorithm sizes and places the children, taking out-of-flow boxes against their containing blocks. Finally boxes are painted in stacking-context order and composited into the frame. Each section of this hub owns one stage of that path: - **Selectors and specificity** is the matching and cascade stage, where "which value" is decided. - **Box model**, **flexbox**, **grid** and **positioning** are the layout stage — four ways the same box gets its size and position. - **Stacking** is the paint stage; it explains overlaps, not sizes. - **Responsive design** and **custom properties** act before layout, changing which values reach it; **animations** re-run part of the pipeline every frame, and which part depends on the property animated. - **Architecture** acts on the cascade stage across a whole codebase. Modern CSS lets several of these meet in one component: ```css @layer reset, components, utilities; @layer components { .card { container-type: inline-size; --gap: 1rem; } .card__body { display: grid; gap: var(--gap); } @container (min-width: 30rem) { .card__body { grid-template-columns: 10rem 1fr; } } } @layer utilities { .gap-lg { --gap: 2rem; } } ``` Putting `gap-lg` on the card wins because its layer comes later, not because its selector is heavier. The new value inherits into the body, and the body switches to two columns when the card is wide, wherever the card sits on the page. Three stages — cascade, computed values, layout — each decide a part.

  1. Selectors and Specificity →

    Which declaration applies at all. Every later section assumes you can predict the winning value.

  2. Box Model and Flow →

    How one box computes its size and how boxes stack in normal flow — the baseline every layout mode departs from.

  3. Flexbox Layout →

    The most used layout mode, and its sizing algorithm is where many middle-level rounds get specific.

  4. Grid Layout →

    Two-dimensional layout, easier once flex is clear, plus the flex-versus-grid choice interviewers like to ask.

  5. Positioning and Stacking →

    Containing blocks and stacking contexts, which explain nearly every overlay, dropdown and sticky header bug.

  6. Responsive Design →

    Media queries, container queries and fluid sizing build on everything above to adapt one layout to any space.

  • Adding an ID or !important to win an override before checking which cascade step decided; a layer or origin difference is settled before specificity is ever consulted.

  • Claiming z-index works on any element, or that a bigger number always wins: it needs a positioned box or a flex or grid item, and it never compares across stacking contexts.

  • Expecting height: 100% to fill a parent whose own height is auto; percentage heights need a definite size to resolve against.

  • Treating flex: 1 and flex-grow: 1 as interchangeable: only the shorthand also resets the basis, which is why items with equal grow values can end up unequal.

  • Fixing overflowing text in a flex row with overflow: hidden on the container, when the cause is the item's minimum size — see the min-width question.

  • Calling margin collapsing a browser bug instead of a defined rule of block flow — one that does not apply between flex or grid items.

  • Answering every responsive question with viewport breakpoints, when a component reused in columns of different widths needs container queries or intrinsic sizing.

  • Animating top, left or width for smooth motion, and shipping motion with no prefers-reduced-motion alternative.

  • Presenting BEM, utility-first or CSS-in-JS as the correct approach instead of naming what each trades away and for which team size it pays off.

CSS has no version number to assume. After CSS 2.1 the language was split into modules that advance independently, so "CSS3" names a period, not a release, and the practical question is always which features the target browsers support. This guide assumes current evergreen browsers. Several features interviewers now expect became usable across all major engines only in recent years: - **Cascade layers**, **`:has()`**, **native nesting**, **subgrid** and **container size queries** are supported in every major engine today. Much advice written before them — "avoid parent selectors", "you need Sass for nesting", "components can only respond to the viewport" — is out of date. - **Native nesting** first required a nested selector to begin with a symbol such as `&`; that restriction was later relaxed, so older examples may look stricter than necessary. - **Media query range syntax**, such as `(width >= 40rem)`, is widely supported and replaces paired `min-`/`max-` conditions. - **Scroll-driven animations**, **`@scope`** and keyword interpolation for sizes such as `height: auto` arrived later and more unevenly across engines; check support before relying on them, and mention the fallback in an answer. When an answer leans on a newer feature, say so and name the fallback. The older techniques — floats and clearfix, `max-height` tricks — still come up, because interviewers ask why a legacy stylesheet looks the way it does.

Plain CSS is rarely written alone, and interviewers expect you to place the tools around it by what each one solves: - **Preprocessors** such as Sass and Less add variables, nesting, mixins and loops at build time. Native custom properties and nesting now cover part of that ground; the lasting difference is that preprocessor output is fixed at compile time, while custom properties change at runtime. - **PostCSS** is a transform pipeline rather than a language: plugins add vendor prefixes, lower newer syntax for older browsers or minify. - **Utility-first frameworks**, Tailwind being the best known, generate single-purpose classes composed in markup. The trade against semantic component classes is the subject of [utility-first vs semantic classes](/topics/fe-css-architecture-utility-first-concept). - **Scoping tools** — CSS Modules, which rewrite class names per file, and CSS-in-JS libraries, which generate styles from component code — attack the global namespace. Shadow DOM encapsulates at the platform level, and `@scope` is the native answer inside ordinary stylesheets; [scoping and encapsulation](/topics/fe-css-architecture-scoping) compares them. A defensible answer names the problem first — runtime theming, name collisions, override wars — and then picks the tool, rather than defending one stack everywhere.

explore

report an issue with this guide →

questions

240 · 8 sections

How does a browser compute a CSS selector's specificity, and how are two selectors' specificity values compared?

level: juniorimportance: must knowfreq 85%
basics
~20 s

Specificity is a three-part count: ID selectors, then class, attribute and pseudo-class selectors, then type selectors and pseudo-elements. Browsers compare the three columns left to right, and the first column that differs decides; identical values fall back to source order.

open as a page

In CSS, which kinds of properties are inherited by default and which are not, and how does inheritance differ from the cascade?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Text-related properties inherit by default: color, the font properties, line-height, letter-spacing, text-align, white-space, list-style, visibility and cursor. Box and painting properties do not: margin, padding, border, background, width, height, display, position, overflow.

open as a page

What does the CSS @layer at-rule do, and how does a layer's position affect which declaration wins?

level: juniorimportance: must knowfreq 48%
basics
~20 s

@layer groups CSS rules into named layers that the cascade compares before it looks at specificity. A declaration in a later-declared layer beats one in an earlier layer, even when the earlier selector is far more specific.

open as a page

In CSS, why does a ::before rule render nothing unless it declares the content property, and what does content: "" actually produce?

level: juniorimportance: must knowfreq 78%
basics
~20 s

A ::before box exists only if the content property generates it — content's initial value computes to none on ::before and ::after, so without it no box is created at all. content: "" generates a real but empty inline box you can then style.

open as a page

In CSS, how do the selectors `.card.featured`, `.card .featured`, and `.card, .featured` differ in what they match?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Written together, .card.featured matches one element carrying both classes. With a space, .card .featured matches a .featured element inside a .card. With a comma, .card, .featured is a selector list: two independent selectors sharing one declaration block.

open as a page

In CSS, an element has `width: 100px`, `padding: 20px`, and `border: 2px solid`. How wide does it actually render under the default `box-sizing`, and what changes if you set `box-sizing: border-box`?

level: juniorimportance: must knowfreq 88%
basics
~20 s

Under the default box-sizing: content-box, width sizes only the content box, so 100px width plus 20px padding on each side plus 2px borders renders 144px wide. With box-sizing: border-box the box stays 100px and the content area shrinks to 56px.

open as a page

In CSS, how do display: block, display: inline, and display: inline-block differ in the way width, height, and vertical margins apply to a box?

level: juniorimportance: must knowfreq 80%
basics
~20 s

A block box takes a whole line and honours width, height and all four margins. A non-replaced inline box flows inside a line of text and ignores width, height and vertical margins. inline-block flows inline but sizes like a block.

open as a page

In CSS, if an img has only its width set and height left at the default auto, what height does it render at and why?

level: juniorimportance: must knowfreq 58%
basics
~10 s

An img is a replaced element carrying an intrinsic width, height and ratio from the image file, so height: auto resolves through that ratio. The rendered height scales proportionally with whatever width you set.

open as a page

In CSS normal flow, one block element has margin-bottom: 30px and the block directly below it has margin-top: 20px. What vertical gap appears between them, and why?

level: juniorimportance: must knowfreq 78%
basics
~10 s

The gap is 30px. Adjoining vertical margins of block boxes in normal flow collapse into one margin equal to the larger value instead of adding up, so the 20px margin contributes nothing extra.

open as a page

In CSS, what is the difference between overflow: auto and overflow: scroll, and which overflow values turn an element into a scroll container?

level: juniorimportance: must knowfreq 70%
basics
~20 s

overflow: scroll always provides a scrolling mechanism whether or not content overflows; overflow: auto provides one only when it does. Both make the element a scroll container, and so does overflow: hidden, which clips and stays scrollable programmatically but shows no scrollbars.

open as a page

In a flex container, how do align-items and align-self differ, and what alignment does an item get when neither is declared?

level: juniorimportance: must knowfreq 70%
basics
~20 s

align-items is declared on the flex container and sets the cross-axis alignment for every item; align-self is declared on one item and overrides it for that item only. With neither set, items use the initial value normal, which behaves as stretch.

open as a page

In Flexbox, how can you tell whether a CSS property belongs on the flex container or on a flex item, and what happens if you declare it on the wrong one?

level: juniorimportance: must knowfreq 58%
basics
~20 s

Container properties set up the layout itself: display, flex-direction, flex-wrap, flex-flow, justify-content, align-items, align-content and gap. Item properties describe one box's own participation: order, flex-grow, flex-shrink, flex-basis, the flex shorthand and align-self. Declared on the wrong box, they are silently ignored.

open as a page

In CSS, what is the difference between display: flex and display: inline-flex on an element?

level: juniorimportance: must knowfreq 62%
basics
~20 s

Both lay the children out identically as flex items. The difference is the container's own box: display: flex is block-level, so it takes its own line and fills the available width, while display: inline-flex is inline-level and sits inside surrounding text.

open as a page

Using CSS Flexbox, how do you center a single child both horizontally and vertically inside its parent, and what does the parent need for the vertical centering to be visible?

level: juniorimportance: must knowfreq 86%
basics
~20 s

Set display: flex, justify-content: center and align-items: center on the parent, and give that parent a height, such as min-height: 100vh. Without a height the parent shrink-wraps its child, so there is no vertical free space to center in.

open as a page

In CSS Flexbox, what do the shorthand values flex: 1, flex: auto, flex: none, and flex: initial each expand to?

level: juniorimportance: must knowfreq 85%
basics
~20 s

flex: 1 expands to flex: 1 1 0%, flex: auto to 1 1 auto, flex: none to 0 0 auto, and flex: initial to 0 1 auto. The three parts, in order, are flex-grow, flex-shrink, and flex-basis.

open as a page

On a CSS Grid container, which single declaration centers every grid item both horizontally and vertically inside its own cell, and what two properties does it expand to?

level: juniorimportance: must knowfreq 66%
basics
~10 s

place-items: center centers every grid item in both axes of its cell. It is the shorthand for align-items (block axis) then justify-items (inline axis), so it expands to align-items: center; justify-items: center.

open as a page

In a CSS Grid container, where do grid items end up if you never set grid-column or grid-row on them?

level: juniorimportance: must knowfreq 62%
basics
~20 s

CSS Grid auto-places any item you do not position: it walks the items in document order and drops each one into the next empty cell, one item per cell, filling row by row because grid-auto-flow defaults to row.

open as a page

In CSS Grid Layout, what is the difference between the explicit grid and the implicit grid?

level: juniorimportance: must knowfreq 70%
basics
~20 s

The explicit grid is the tracks you declare yourself with grid-template-columns, grid-template-rows or grid-template-areas. The implicit grid is the extra rows or columns the browser generates on its own when items need space outside what you declared.

open as a page

In CSS Grid, an item is styled `grid-column: 1 / 3`. What do the numbers 1 and 3 refer to, and how many columns does the item occupy?

level: juniorimportance: must knowfreq 72%
basics
~20 s

They are grid line numbers, not column numbers. The item starts at column line 1 and ends at column line 3, so it covers the two tracks between them — the first and second columns.

open as a page

In CSS Grid, what does the track size minmax(200px, 1fr) mean when used in grid-template-columns?

level: juniorimportance: must knowfreq 60%
basics
~20 s

minmax(200px, 1fr) gives a grid column a 200px floor and a flexible ceiling: the track is never narrower than 200px, but it grows beyond that to absorb its share of the container's leftover free space.

open as a page

In CSS, how do you make an element a query container named card and apply styles only when that container is at least 400px wide?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Set container-type: inline-size and container-name: card on the wrapper, or the shorthand container: card / inline-size, then put the rules inside @container card (min-width: 400px). Those rules style the container's descendants, not the container itself.

open as a page

What does the CSS clamp() function do with its three arguments, and how would you use it to make a heading's font-size scale with the viewport?

level: juniorimportance: must knowfreq 70%
basics
~20 s

clamp(MIN, PREFERRED, MAX) returns the preferred value when it lies between the bounds, MIN when it falls below, and MAX when it rises above. font-size: clamp(1.5rem, 4vw, 3rem) scales a heading with the viewport but never below 1.5rem or above 3rem.

open as a page

What does "mobile-first" mean in a CSS stylesheet, and why does it favour min-width media queries over max-width ones?

level: juniorimportance: must knowfreq 76%
basics
~10 s

Mobile-first means the unconditional base rules describe the narrowest layout, and min-width media queries add complexity as the viewport grows. Because narrow screens are the default, the stylesheet accumulates enhancements instead of overrides.

open as a page

What does the tag <meta name="viewport" content="width=device-width, initial-scale=1"> do, and what happens to a responsive page on a phone if it is omitted?

level: juniorimportance: must knowfreq 70%
basics
~20 s

It tells a mobile browser to make the layout viewport the device's own width at 100% zoom, instead of a wide fallback of roughly 980 CSS pixels. Without it, a phone lays the page out wide and shrinks the whole thing down.

open as a page

Why can a reusable card component not be made truly responsive with CSS @media queries alone, and what do container queries change?

level: middleimportance: must knowfreq 68%
basics
~20 s

@media queries only test the viewport, so one card gets the same breakpoint in a wide main column and in a narrow sidebar. Container queries let a component respond to the size of its own container instead.

open as a page

In CSS, how do you declare a custom property and use it in a value with var(), and what does the second argument in var(--name, fallback) do?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Declare a custom property as a normal declaration whose name starts with two dashes, such as --gap: 12px, and read it back with var(--gap). The optional second argument, var(--gap, 8px), applies only when --gap is not defined.

open as a page

In CSS, what can a @keyframes animation express that a transition cannot, and what starts each of them?

level: juniorimportance: must knowfreq 78%
basics
~20 s

A CSS transition interpolates between two states and only runs when a value actually changes, typically on :hover or a class toggle. A @keyframes animation declares many intermediate stops, starts on its own, and can loop, alternate direction, and be paused.

open as a page

In CSS, what does the declaration `transition: opacity 300ms ease-in 100ms;` set, and how does the browser decide which of the two time values is the duration and which is the delay?

level: juniorimportance: must knowfreq 78%
basics
~20 s

It animates only opacity over 300ms with an ease-in curve, starting after a 100ms delay. In the transition shorthand the components are order-free by type, except that the first time value is always the duration and the second is the delay.

open as a page

How do CSS custom properties differ from Sass variables, and what can you do with one that you cannot do with the other?

level: middleimportance: must knowfreq 66%
basics
~20 s

CSS custom properties are real values in the cascade: they inherit, can be redefined per selector or per element, and the browser resolves them at computed-value time. Sass variables are compile-time text that never reaches the browser.

open as a page

In CSS, what does animation-fill-mode do, and what are the practical differences between none, forwards, backwards, and both?

level: middleimportance: must knowfreq 62%
basics
~20 s

animation-fill-mode decides whether keyframe values apply outside the animation's active run. The default none applies nothing before or after; forwards holds the final keyframe after it ends; backwards applies the first keyframe during the delay; both does each.

open as a page

In CSS, how do position: relative and position: absolute differ in their effect on normal flow, and what are their top/left offsets measured from?

level: juniorimportance: must knowfreq 82%
basics
~20 s

A relatively positioned box keeps its space in normal flow and is only shifted visually from where it would have been. An absolutely positioned box is removed from flow entirely and offset from its containing block instead.

open as a page

In CSS, how does position: sticky differ from position: fixed for a page header?

level: juniorimportance: must knowfreq 70%
basics
~20 s

position: sticky keeps the element in normal flow and pins it only after scrolling reaches the inset threshold you declared, inside its nearest scrolling ancestor. position: fixed removes the element from flow and pins it to the viewport from the start.

open as a page

In CSS, on which elements does the z-index property actually have an effect?

level: juniorimportance: must knowfreq 70%
basics
~20 s

z-index applies to positioned elements — those with position relative, absolute, fixed, or sticky — and also to flex items and grid items, which honour z-index even while position stays static. On any other element the declaration is ignored.

open as a page

In CSS, why does a container whose children are all floated collapse to zero height, and what makes it contain them again?

level: middleimportance: must knowfreq 62%
basics
~20 s

A block container with auto height measures only its in-flow children, and floats are out of flow, so it collapses. Make it contain floats by giving it display: flow-root, or add a cleared element after the floats.

open as a page

A dropdown panel positioned with `position: absolute` is cut off at the edge of a card whose CSS sets `overflow: hidden`. What decides whether an ancestor's overflow clips a positioned descendant, and what are the ways out?

level: middleimportance: must knowfreq 56%
basics
~20 s

An element with clipped overflow clips only descendants whose containing block is that element or something inside it. A positioned panel whose containing block is higher up escapes the clip — which is why position: fixed, or mounting the panel at the document root, fixes it.

open as a page

In the BEM CSS naming methodology, what do "block", "element" and "modifier" mean, and how does each one appear in a class name?

level: juniorimportance: must knowfreq 72%
basics
~10 s

BEM names classes after a block (a standalone component, .card), its elements (parts that exist only inside it, .card__title), and modifiers (variant flags, .card--featured). Two underscores mark an element, two hyphens mark a modifier.

open as a page

In CSS, why is a class rule such as .title { color: red } described as living in a global namespace, and what problems does that create in a large codebase?

level: juniorimportance: must knowfreq 55%
basics
~20 s

CSS selectors are matched against the entire document regardless of which file they were written in, so one .title rule styles every element with that class. Collisions are silent, and unrelated components end up restyling each other.

open as a page

Most CSS style guides tell you to style a component with a single class like `.card__title` instead of a chain like `#main .card h2`. Both match the same heading — what does the flat single-class convention buy a growing codebase?

level: juniorimportance: must knowfreq 62%
basics
~20 s

A single class keeps every rule at the same low weight, so a later rule can override it by source order alone. IDs and long descendant chains raise the weight, forcing every future override to be heavier still.

open as a page

In CSS architecture, what does a "utility-first" approach mean compared with writing semantic component classes, and what trade do the two make against each other?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Utility-first composes many single-purpose classes in the markup, each setting one or two declarations. The semantic approach puts one meaning-based class on the element and defines all its styling in the stylesheet. The trade is markup noise versus an ever-growing stylesheet.

open as a page

In a codebase where each UI component ships with its own stylesheet file, which kinds of CSS legitimately belong in the shared global stylesheet instead, and which do not?

level: middleimportance: must knowfreq 62%
basics
~20 s

Global CSS holds what must exist exactly once for the whole document: the reset, @font-face declarations, custom-property definitions on :root, base element typography, and a small utility set. Anything describing one component belongs in that component's file.

open as a page
CSS interview questions & primer · KataJob