HTML & CSS Senior cheat sheet: interview answers

Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.

Quick reference: Key concepts and pitfalls on a couple of pages →
  1. 1. How do @layer cascade layers affect style priority?

    Correct answer: Layer order beats specificity: the later layer wins

    The cascade compares layers first and only then specificity within a layer. So .btn in the components layer beats #app .btn in an earlier base layer. Unlayered styles are stronger than any layer. For !important the order is reversed: important declarations in an earlier layer win. Tailwind v4 builds its styles on the theme, base, components and utilities layers.

  2. 2. How do normal (non-!important) layered and unlayered styles rank against each other?

    Correct answer: Unlayered styles are stronger than any layer

    Unlayered styles implicitly go into a "last" layer and beat all named layers. That lets you wrap third-party CSS in @layer vendor and easily override it with your own styles. With !important the logic flips: important layered styles beat important unlayered ones.

  3. 3. What does @scope (.card) to (.card__content) { img { ... } } do?

    Correct answer: Styles img inside .card, but not inside .card__content

    @scope defines a scope root and an optional "lower boundary" (donut scope): styles apply inside .card but don't reach into .card__content and its descendants. In addition, with equal specificity the rule with the closer root wins (scoping proximity). @scope doesn't create a Shadow DOM.

  4. 4. What problem does subgrid solve?

    Correct answer: It gives a nested grid its parent's tracks, aligning parts across cards

    With grid-template-rows: subgrid a child grid inherits the parent's lines. The classic example is a row of cards whose titles, text and buttons should line up even when one card's title wraps to two lines. Without subgrid, each card aligns independently.

  5. 5. Which stages does the browser go through to update a frame after a style change?

    Correct answer: Style → Layout → Paint → Composite

    The rendering pipeline: style recalculation (Style) → geometry (Layout/Reflow) → painting layer pixels (Paint) → layer composition (Composite). Changing width runs everything from Layout, changing color from Paint, while transform and opacity can get away with Composite alone.

  6. 6. What is layout thrashing (forced synchronous layout)?

    for (const el of items) {
      el.style.width = box.offsetWidth + "px";
    }

    Correct answer: Repeated layout from interleaved reads and writes

    Reading offsetWidth after writing a style forces the browser to recalculate layout synchronously to return an up-to-date value. In a loop this happens on every iteration. The fix is to read all values first, then write (batch reads/writes), or move the read out of the loop. Libraries like fastdom help too.

  7. 7. What does contain: layout paint (or contain: content) give you?

    Correct answer: A promise that contents don't affect outside layout and paint, narrowing recalculation

    CSS Containment isolates a subtree: changes inside don't force layout and paint of the rest of the page. Useful for widgets, feeds and complex components. Side effect: paint clips content to the bounds and creates a containing block and a stacking context, so don't apply it thoughtlessly.

  8. 8. How does content-visibility: auto speed up long pages?

    Correct answer: It skips layout and paint of off-screen elements until they're needed

    The browser doesn't render sections outside the viewport, saving time on the first paint. To keep the scrollbar from jumping, set an expected size via contain-intrinsic-size: auto 500px. The DOM stays intact: find-in-page and accessibility keep working, unlike virtualization.

  9. 9. Why don't ::before and ::after work on <img> and <input>?

    Correct answer: They are replaced or void elements - there's no content to insert into

    ::before/::after are inserted inside the element, before and after its content. The content of <img>, <video>, <iframe> is replaced by an external resource, while <input> and <br> are void elements. The workaround is to wrap the element in a container and attach the pseudo-element to it. display is irrelevant: pseudo-elements work on an inline <span>.

  10. 10. What is float still appropriate for in modern layouts?

    Correct answer: For wrapping text around an image or a pull quote inside an article

    Page layouts have long been built with Flexbox and Grid, but text wrapping - float's original purpose - has no replacement. Combined with shape-outside, text can even wrap along an image's shape. The property is neither deprecated nor removed.

  11. 11. Why is em often recommended over px for media query breakpoints?

    Correct answer: em in media queries respects the user-set font size

    In media queries, em and rem are based on the browser's initial font size (usually 16px), not on page styles. If a user enlarges the base font, the layout switches to the "narrow" version sooner - text won't be cramped. With px that doesn't happen. Tailwind v4 defines breakpoints in rem for the same reason.

  12. 12. What happens to a position: fixed element if an ancestor has transform: translateZ(0)?

    Correct answer: It becomes positioned relative to that ancestor

    An ancestor with transform, filter, perspective, contain: paint or will-change: transform becomes the containing block for fixed descendants. A modal inside an animated container suddenly "sticks" to the container instead of the window. That's why modals and toasts are rendered through a portal at body level.

  13. 13. How does overflow: clip differ from overflow: hidden?

    Correct answer: clip clips without creating a scroll container and doesn't break sticky

    overflow: hidden makes the element a scroll container (it can be scrolled programmatically), so sticky descendants start sticking to it. clip simply clips painting, forbids any scrolling and doesn't create a BFC. Axes can be controlled separately (overflow-x: clip), and a clip margin can be set with overflow-clip-margin.

  14. 14. How should Sass modules be included now that @import is deprecated?

    Correct answer: With namespaced @use and @forward for re-exporting

    @use 'tokens' loads a module once and namespaces it (tokens.$primary) without polluting the global scope. @forward re-exports a module's members to build a style library's public API. Sass @import is deprecated and will be removed in Dart Sass 3.0. There's no @require directive.

  15. 15. How does Dart Sass differ from Node Sass?

    Correct answer: Node Sass (LibSass) is deprecated; Dart Sass is the primary implementation

    LibSass and Node Sass are deprecated and don't support @use or the module system. Dart Sass is the reference implementation, published on npm as sass (and sass-embedded). Migration means removing node-sass, installing sass, and gradually moving from @import to @use and from / division to math.div.

  16. 16. What problems does runtime CSS-in-JS (styled-components, Emotion) have with SSR and React Server Components?

    Correct answer: Styles are created at runtime, with no RSC context

    Runtime CSS-in-JS computes styles during render and injects them into the document: on the server the styles must be collected and inlined into HTML (otherwise you get a flash), and on the client you pay the runtime cost. They rely on React Context, which Server Components lack, so such components must be client components. Alternatives: CSS Modules, Tailwind, zero-runtime solutions (vanilla-extract, Linaria, Panda).

  17. 17. Which techniques reduce the weight and performance impact of a custom web font?

    Correct answer: WOFF2, subsetting, preload of the main weight and font-display

    WOFF2 compresses best. Subsetting removes unused glyphs (e.g. keeping only Latin and Cyrillic), and unicode-range lets the browser download only the subsets it needs. preload speeds up the main weight, font-display removes invisible text. A variable font replaces several weight files with one. In Next.js, next/font handles much of this.

  18. 18. How does asset bundling strategy change when moving from HTTP/1.1 to HTTP/2+?

    Correct answer: Multiplexing makes requests cheaper, so smaller chunks pay off

    With HTTP/1.1 browsers keep ~6 connections per domain, so we concatenated files, used sprites and domain sharding. HTTP/2 and HTTP/3 multiplex requests over one connection, making those hacks less necessary or even harmful: one huge bundle invalidates the whole cache on any change. Dropping bundling entirely is still rare - compression and import chains still matter.

  19. 19. What is a performance budget?

    Correct answer: Agreed limits on metrics (JS weight, LCP) that are checked in CI

    A performance budget fixes thresholds - e.g. "homepage JS ≤ 170 KB gzipped" or "LCP ≤ 2.5 s on 4G" - checked automatically (Lighthouse CI, size-limit, bundlesize). Regressions are caught before release, and decisions about new libraries take their cost into account.

  20. 20. How does lab data (Lighthouse) differ from field data (CrUX, RUM)?

    Correct answer: Lab is a controlled measurement; field data comes from real users

    Lab data is reproducible and handy for debugging but doesn't reflect the real variety of devices, networks and scenarios. Field data (Chrome UX Report, your own RUM via web-vitals) shows what users actually experience, and Google assesses Core Web Vitals from it. INP can't even be measured in the lab without real interactions.

  21. 21. Which three metrics make up Core Web Vitals today?

    Correct answer: LCP, INP and CLS

    LCP - loading speed of the main content (good ≤ 2.5 s), INP - responsiveness to interactions (≤ 200 ms), CLS - visual stability (≤ 0.1). INP replaced FID in March 2024 because FID only measured the delay of the first interaction. FCP and TBT are useful but supporting metrics.

  22. 22. How do you build a horizontal gallery with slides that "snap" into place without JavaScript?

    Correct answer: scroll-snap-type: x mandatory on the track, scroll-snap-align on slides

    CSS Scroll Snap: a container with overflow-x: auto and scroll-snap-type: x mandatory, slides with scroll-snap-align. The browser settles the scroll on the nearest slide and supports touch, wheel and keyboard. scroll-padding accounts for fixed elements. JS is only needed for prev/next buttons and indicators.

  23. 23. What does @property --angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; } enable?

    Correct answer: Declaring a typed variable that the browser can animate

    A regular CSS variable is just a string, so it jumps during animation. A property registered with @property (part of Houdini) has a type and therefore animates smoothly: that's how rotating conic gradients and animating individual color channels are done. You can also disable inheritance and set an initial value.

  24. 24. How do you style the inside of a Web Component when Shadow DOM isolates its styles?

    Correct answer: Through CSS variables (they inherit across the boundary) and ::part()

    Outside selectors don't reach into a shadow root, even with !important. But inherited properties (color, font) and custom properties cross the boundary - theming is built on them. The component author can expose parts via part="label", which are styled from outside with my-el::part(label). Slotted content (light DOM) is styled with regular CSS.

  25. 25. How do min-content, max-content and fit-content differ as width values?

    Correct answer: Minimum by the longest word, width without wrapping, and capped max-content

    These are intrinsic sizes that depend on content. width: fit-content is handy for fluid badges and buttons that shouldn't stretch to full width. In Grid they're used in track definitions: grid-template-columns: max-content 1fr.

  26. 26. What creates a new stacking context even without position and z-index?

    Correct answer: opacity below 1, transform, filter, isolation: isolate

    A stacking context is created by: the root element, positioned elements with z-index, flex/grid items with z-index, opacity < 1, transform, filter, perspective, mix-blend-mode, isolation: isolate, contain: paint, and will-change with such properties. isolation: isolate is the "cleanest" way to create one without side effects.

  27. 27. What conditions make the vertical margins of a parent and its first child collapse?

    Correct answer: No border, padding or text separates them

    The first child's margin-top "falls through" outside the parent if nothing separates them. Collapsing is prevented by padding or border on the parent, display: flow-root, or a flex/grid container - margins inside those never collapse. With negative values, the result is the largest positive plus the most negative.

  28. 28. Why can a long word or a wide table "blow out" a 1fr grid column?

    Correct answer: 1fr means minmax(auto, 1fr): the track can't be narrower than min-content

    For fr tracks the default minimum is auto, i.e. no smaller than the minimum content. A wide item grows the track, and the columns stop being equal. The fix is minmax(0, 1fr) in the track definition or min-width: 0 / overflow: hidden on the item.

  29. 29. Why is oklch() more convenient than hsl() for design systems?

    Correct answer: It's perceptually uniform: equal L looks equally light across hues

    In HSL, yellow and blue with the same "lightness" look completely different, so palettes must be tuned by hand. OKLCH is based on a perception model, so shade scales are generated predictably, which simplifies contrast. Tailwind v4's default palette is defined in OKLCH.

  30. 30. What is color-mix(in oklch, var(--brand) 80%, white) for?

    Correct answer: Mixing colors in CSS - a light brand tint without hardcoding

    color-mix() blends colors in a given color space at a given ratio. It lets you derive hover states, translucent variants (color-mix(in srgb, red, transparent 50%)) and tints from a single brand variable. Tailwind v4 uses it to implement opacity modifiers like bg-brand/50.

  31. 31. What does native CSS nesting (&) give you?

    .card {
      padding: 1rem;
      &:hover { background: #eee; }
      .title { font-weight: 600; }
    }

    Correct answer: Browsers understand nesting natively; & refers to the parent selector

    CSS Nesting is supported by all modern browsers. Differences from Sass: nested selectors behave as if wrapped in :is(), which affects specificity, and you can't concatenate strings like &__title - that's a preprocessor-only feature.

  32. 32. What is CSS Anchor Positioning used for?

    Correct answer: Tethering a tooltip or popover to another element without JS calculations

    An anchor is declared with anchor-name: --btn, and the positioned element references it via position-anchor and the anchor() function (or position-area). Fallbacks exist for lack of space (position-try-fallbacks). This used to require libraries like Floating UI. Browser support isn't complete everywhere yet - check it before use.

  33. 33. What is the View Transitions API?

    Correct answer: An API for animating transitions between DOM states or pages

    document.startViewTransition(() => updateDOM()) captures the old state, applies the changes and animates the transition via ::view-transition-old/new pseudo-elements, styled with regular CSS. MPAs get cross-document transitions via @view-transition. React 19.2 added a <ViewTransition> component.

  34. 34. What is the minimum required for an accessible modal dialog?

    Correct answer: Focus moved inside and trapped, Esc, focus restored, inert background

    Keyboard and screen reader users must get into the modal, not "fall out" of it with Tab, close it and return where they were. A native <dialog> with showModal() does most of this: the background becomes inert, Esc closes it, focus moves. You also need a label via aria-labelledby. aria-hidden on the modal would hide it from screen readers instead.

  35. 35. What does the inert attribute do?

    Correct answer: Makes a subtree non-interactive and hidden from assistive technologies

    inert is the native way to "switch off" part of a page: for example, the main content while a drawer is open. Previously you had to manually set tabindex="-1" on every focusable element plus aria-hidden. A modal <dialog> makes the rest of the document inert automatically.

  36. 36. What minimum text contrast does WCAG level AA require for normal text?

    Correct answer: 4.5:1 for normal text

    AA: 4.5:1 for normal text and 3:1 for large text (from 24px, or ~18.7px bold), as well as for UI components and meaningful graphics. 7:1 is the AAA requirement. Level AA is the standard target and a legal requirement in many countries (EN 301 549 in the EU, ADA in the US in practice).

  37. 37. How do WCAG conformance levels A, AA and AAA differ?

    Correct answer: Strictness levels: A - minimum, AA - the usual target, AAA - maximum

    Each WCAG success criterion has a level. A covers basics (alt text, keyboard operation), AA adds contrast, visible focus and consistent navigation, AAA adds strict requirements such as 7:1 contrast and sign language for video. Versions of the standard are 2.0, 2.1 and 2.2.

  38. 38. When are ARIA attributes needed, and when is it better to do without them?

    Correct answer: If a native element exists, use it; ARIA is for custom widgets

    ARIA only changes how an element is described to assistive technologies; it adds no behavior: <div role="button"> doesn't get focus or Enter/Space activation. Incorrect ARIA is worse than none. For tabs, comboboxes and trees, which have no native equivalents, follow the APG patterns.

  39. 39. What does text-wrap: balance do on a heading?

    Correct answer: Distributes words so the lines are roughly equal in length

    balance chooses line breaks so a multi-line heading's lines are close in length - no orphaned last word. The algorithm is expensive, so browsers apply it only to short blocks (a few lines). For paragraphs there's text-wrap: pretty, which avoids a single word on the last line. Justification is text-align: justify.

  40. 40. What are HTML landmarks, and why do they matter?

    Correct answer: Regions (header, nav, main…) for quick screen reader navigation

    Semantic elements implicitly get landmark roles (banner, navigation, main, complementary, contentinfo). Screen reader users open a list of landmarks and jump to the one they need. If a page has several nav elements, give them distinct names via aria-label. A typical SPA problem is a missing main or several visible ones.

  41. 41. Which accessibility problem is typical for SPAs when the "page" changes on the client?

    Correct answer: Screen readers aren't told about the navigation: focus and title don't change

    On a full reload the browser announces the new page itself. SPAs don't get that, so you need to update document.title, move focus to the heading or main, or announce the change via a live region. The Next.js App Router does part of this (route announcer). Screen readers read JS-rendered content just fine.

  42. 42. How does Tailwind v4 fundamentally differ from v3?

    Correct answer: CSS-first config via @theme, a new engine, automatic source detection

    Tailwind v4 is a rewrite: it's included with a single @import "tailwindcss", tokens are defined in CSS via @theme and exposed as CSS variables, and you no longer list paths in content - sources are detected automatically. Builds are much faster, and styles use @layer, @property and color-mix(). Modern browsers are required.

  43. 43. How do you make Tailwind v4's dark mode follow a .dark class instead of the system setting?

    Correct answer: Override the variant: @custom-variant dark (&:where(.dark, .dark *));

    In v4, variants are defined in CSS with @custom-variant. That way dark: can be bound to a class or an attribute ([data-theme=dark]). darkMode: 'class' is a v3 tailwind.config.js option and doesn't work inside @theme. :where() keeps specificity from increasing.

  44. 44. You're designing the CSS architecture of a multilingual site including Arabic (RTL) and Japanese. What should you plan for?

    Correct answer: Logical properties, lang/dir attributes, flexible containers for text

    Logical properties (margin-inline-start, inset-inline-end) mirror the layout automatically for RTL with dir="rtl". lang is needed for correct fonts, hyphenation and quotes, and :lang() for language-specific styles. Text length varies across languages, so fixed widths break. CJK needs its own fonts and line-breaking rules (word-break, line-break).

  45. 45. Which approach to fluid typography best respects the user's font scaling?

    Correct answer: clamp(1rem, 0.8rem + 1vw, 1.5rem) - smooth growth within bounds

    Pure vw ignores the user's font size setting and barely changes on zoom - a WCAG problem (resize text up to 200%). Mixing rem + vw inside clamp() gives smooth scaling while still responding to user settings. Pixel steps work but jump between breakpoints.

  46. 46. A 10,000-row table lags when scrolling. Which solution is most effective?

    Correct answer: Virtualization: render only the visible rows plus a small buffer

    The main problem is thousands of DOM nodes: memory, layout and styles. Virtualization (TanStack Virtual, react-window) keeps dozens of rows in the DOM and swaps them while scrolling. will-change on thousands of elements eats memory. Changing the markup doesn't reduce node count. Simpler alternatives are pagination or content-visibility.

  47. 47. A gallery with 50 YouTube videos loads very slowly. What should you do first?

    Correct answer: Show preview images and insert the <iframe> only on click

    Each YouTube iframe pulls hundreds of kilobytes of JS and many requests. The facade pattern (e.g. lite-youtube-embed) shows a static thumbnail and swaps in the player only on interaction. loading="lazy" on iframes also helps. autoplay=0 doesn't reduce the embed's weight.

  48. 48. How does preload differ from prefetch in <link rel>?

    Correct answer: preload is urgent for the current page, prefetch is in advance for the next one

    preload says "this resource is definitely needed now, start early" - e.g. a font or an LCP image discovered late. prefetch is a hint for the future, loaded during idle time. An unnecessary preload steals bandwidth from critical resources. There's also preconnect to set up a connection to a domain early.

  49. 49. How does defer differ from async on <script>?

    Correct answer: defer runs in order after HTML parsing, async runs as soon as it loads

    A regular script stops the parser. defer downloads in parallel and executes in order before DOMContentLoaded - good for dependent application scripts. async executes as soon as it's downloaded - for independent scripts like analytics. Modules (type="module") behave like defer by default. Neither attribute affects inline scripts.

  50. 50. A designer insists on fully custom styles for every control in a complex form. What's a sensible approach?

    Correct answer: Style the native controls (appearance: none, accent-color)

    Native controls give you accessibility, keyboard support, autofill and mobile pickers for free. Most of their appearance can be changed via appearance: none, accent-color, pseudo-elements and :checked / :focus-visible. Hand-made <div> widgets require full ARIA pattern implementations - expensive and risky. Discuss the trade-offs with the designer.

  51. 51. What does font-size: 5cqi mean inside a container query?

    Correct answer: 5% of the query container's inline size

    Container query units (cqw, cqh, cqi, cqb) resolve against the nearest container with container-type. A card can then size its typography for wherever it is placed.

  52. 52. Why style errors with :user-invalid instead of :invalid?

    Correct answer: It matches only after the user has interacted

    :invalid applies immediately, punishing users before they type. :user-invalid gives the "touched" behavior that previously needed JavaScript.

  53. 53. What does the popover attribute give you?

    <button popovertarget="menu">Menu</button>
    <div id="menu" popover>...</div>

    Correct answer: A top-layer element with light dismiss

    The top layer sits above all z-index stacking contexts, so overflow and stacking bugs disappear. Unlike <dialog> with showModal(), a popover doesn't make the rest of the page inert.

  54. 54. What problem does @starting-style solve?

    .toast { opacity: 1; transition: opacity 0.3s, display 0.3s allow-discrete; }
    @starting-style { .toast { opacity: 0; } }

    Correct answer: It defines the "before" values for entry transitions

    Without a starting style, newly displayed elements render directly in their final state. Combined with transition-behavior: allow-discrete, enter and exit animations work in pure CSS.

  55. 55. What do scroll-driven animations (animation-timeline: scroll()) allow?

    Correct answer: Linking animation progress to scroll position

    view() timelines tie progress to an element's visibility in the viewport. Running on the compositor, they avoid the jank of scroll event listeners.

  56. 56. What does color: light-dark(#111, #eee) do?

    Correct answer: Picks a value by the active color scheme

    It requires color-scheme: light dark (or a specific scheme) on the element or root. It reduces the number of duplicated variable definitions in media queries.

  57. 57. What does hyphens: auto need to work correctly?

    Correct answer: A correct lang attribute on the page

    It helps narrow columns in languages with long words (German, Ukrainian). overflow-wrap: anywhere is the fallback for strings like URLs.

  58. 58. Why use font-variant-numeric: tabular-nums in tables and timers?

    Correct answer: All digits get the same width

    Many fonts use proportional digits by default ("1" is narrower than "0"). Tailwind exposes this as the tabular-nums utility.

  59. 59. What is the main advantage of a variable font?

    Correct answer: One file holds a range of weights and widths

    Instead of downloading 400, 500, 600 and 700 separately, you load one file and use any weight in between. It pays off when you use three or more styles.

  60. 60. How does size-adjust in a fallback @font-face reduce layout shift?

    Correct answer: It scales the fallback to match the web font

    Together with ascent-override and descent-override it makes the fallback occupy nearly the same space. Next.js next/font generates such adjusted fallbacks automatically.

  61. 61. What does fetchpriority="high" on the hero image do?

    Correct answer: Asks to fetch it ahead of other images

    Browsers discover many images at once and initially treat them all as low priority. Use it for one or two critical resources; marking everything high cancels the effect.

  62. 62. Why add isolation: isolate to a component root?

    Correct answer: To create a stacking context for the component

    It creates a stacking context without side effects like position or transform. Internal z-index: 10 then only competes with siblings inside the component.

  63. 63. What does overscroll-behavior: contain on a scrollable modal body prevent?

    Correct answer: Scroll chaining to the page behind it

    It also suppresses pull-to-refresh and overscroll glow on mobile inside that container. Useful for chat panes, sidebars and modals.

  64. 64. What layout shift does scrollbar-gutter: stable prevent?

    Correct answer: Content jumping when a scrollbar appears

    It reserves space for the scrollbar even when content doesn't overflow. It matters on systems with non-overlay scrollbars (most Windows setups).

  65. 65. What happens to your colors in Windows High Contrast (forced colors) mode?

    Correct answer: The system replaces most colors on the page

    Focus rings made with box-shadow or states shown only by background color can disappear. A transparent outline stays visible because the system paints it.

  66. 66. What is a skip link?

    <a href="#main" class="skip-link">Skip to content</a>

    Correct answer: A first link that jumps past the navigation

    It is usually visually hidden until focused. Without it, keyboard users tab through the whole header on every page.

  67. 67. How do you correctly associate an error message with an input?

    <input id="email" aria-invalid="true" aria-describedby="email-error" />
    <p id="email-error">Enter a valid email</p>

    Correct answer: With aria-invalid and aria-describedby

    Screen readers then read the error when the field is focused. Color alone fails WCAG for users who can't distinguish it.

  68. 68. What does the WCAG "Reflow" criterion require?

    Correct answer: Content works at 320 CSS px without side scrolling

    A responsive layout usually satisfies it; fixed-width containers and overflow-x on the body break it.

  69. 69. What does WCAG 2.2 "Target Size (Minimum)" ask for?

    Correct answer: Targets of at least 24×24 CSS px

    Inline links in text are exempt. Platform guidelines recommend even larger touch targets (44–48px) for primary controls.

  70. 70. Why do build tools emit CSS files with content hashes (app.3f9a1c.css)?

    Correct answer: So files can be cached "forever"

    The HTML referencing the file is short-lived; the asset itself never changes under the same name. This avoids users getting stale styles after a deploy.

  71. 71. Why split design tokens into primitive and semantic layers?

    --blue-600: oklch(0.55 0.2 260);      /* primitive */
    --color-action: var(--blue-600);      /* semantic */

    Correct answer: Themes change the mapping, not every component

    Dark mode or a new brand only remaps --color-action. Components referencing --blue-600 directly would all need edits.

  72. 72. Why use dir="auto" on user-generated content such as comments?

    Correct answer: The browser detects text direction from the content

    Mixed-direction text without it shows punctuation and numbers in the wrong places. <bdi> isolates short inline snippets like usernames.

  73. 73. Why prefer IntersectionObserver over scroll listeners for lazy loading or reveal effects?

    Correct answer: It reports visibility without forcing layout

    Scroll handlers that call getBoundingClientRect() run dozens of times per second and can cause layout thrashing. The observer batches checks off the critical path.

  74. 74. Why avoid @import inside plain CSS files?

    Correct answer: It creates a chain of render-blocking requests

    Use <link> tags or a bundler that inlines imports at build time. In Sass, @use is compiled away, so this doesn't apply to it.

  75. 75. What does li:nth-child(2 of .visible) select?

    Correct answer: The second li among those that have the class visible

    The of S syntax filters before counting, which fixes zebra striping in filtered lists. Plain :nth-child(2).visible counts all siblings first.