CSS Tutorial 0/203 lessons ~6 min read Lesson 172

    Beginner: Selectors

    beginner: selectors selectors — 25 interview questions with traps, follow-ups, and production context. practice out loud; staff loops reward trade-offs,

    Course progress0%
    Focus
    16 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Selectors — 25 interview questions with traps, follow-ups, and production context. Practice out loud; staff loops reward trade-offs, not definitions.

    Business problem

    Business pressure: Product teams need Selectors interview questions to ship polished UI without layout regressions, accessibility lawsuits, or LCP regressions that hurt conversion.

    • Conversion: Visual polish and performance directly affect checkout and signup funnels.
    • Brand: Inconsistent Selectors interview questions implementation fragments design system trust.
    • Velocity: CSS debt slows every feature team — architecture matters at scale.

    Why this feature exists

    Platform history: CSS evolved Selectors interview questions to solve author needs without JavaScript layout engines or table hacks.

    • Problem solved: Declarative styling separated from document structure.
    • Rejected alternative: Inline styles and JS layout — unmaintainable at enterprise scale.

    Browser rendering perspective

    Rendering impact: Selectors interview questions affects style recalculation, layout, paint, and composite stages in the browser pipeline.

    • Chrome (Blink): Style → LayoutNG → Paint → Viz compositor.
    • Firefox (Gecko): Servo-based stylo + WebRender compositing.
    • Safari (WebKit): WebKit style resolver + GPU layer promotion rules.

    Internal browser workflow

    Workflow: Selector match → cascade → computed values → layout tree → paint layers → composite.

    Real production example

    Production: Netflix, Amazon, and Shopify enforce Selectors interview questions patterns via design tokens, lint rules, and visual regression CI.

    Enterprise use case

    Enterprise: Design systems (Polaris, Carbon, Atlassian) codify Selectors interview questions in token pipelines and component APIs.

    Accessibility considerations

    A11y: CSS must not remove focus visibility, break zoom, or convey state by color alone (WCAG 2.2).

    Performance considerations

    Performance: Selectors interview questions can trigger reflow, expensive selectors, or layer explosion — profile with DevTools Performance panel.

    SEO considerations

    SEO: CSS affects LCP, CLS, and mobile usability — ranking signals tied to Core Web Vitals.

    Scalability considerations

    Scale: Selectors interview questions choices compound across micro-frontends, white-label tenants, and dark-mode variants.

    Common production issues

    Production failures: Specificity wars, z-index stacks, and responsive breakpoints that work in Chrome but break Safari.

    Debugging guide

    Debug: Chrome DevTools → Elements (computed styles), Layout panel, Rendering layers, Coverage for unused CSS.

    Interview questions

    What is a type selector?(Beginner)

    Selects elements by tag name (div, p). Trap: too broad — styles leak globally without scoping.

    Follow-up: Why prefer classes over div {}

    What is a class selector?(Beginner)

    .classname — reusable, lower specificity than id. Trap: chaining many classes for specificity arms race.

    Follow-up: BEM naming benefit?

    What is an attribute selector?(Beginner)

    [type=email] selects by attribute — useful for forms. Trap: case sensitivity depends on attribute.

    Follow-up: [href^=https] use case?

    What is descendant combinator?(Beginner)

    A B — B anywhere inside A. Trap: deep descendant selectors are slow and brittle.

    Follow-up: Child vs descendant?

    What is child combinator?(Beginner)

    A > B — direct children only — tighter than descendant.

    Follow-up: When prefer child combinator?

    What is adjacent sibling?(Beginner)

    A + B — B immediately after A. Trap: only one sibling, not all following.

    Follow-up: General sibling vs adjacent?

    What is general sibling?(Beginner)

    A ~ B — all B siblings after A sharing parent.

    Follow-up: Use case for ~?

    What is :not() pseudo-class?(Beginner)

    Negates simple selector in list — :not(.disabled) enables exceptions without override wars.

    Follow-up: :not() specificity rules?

    What is :is() pseudo-class?(Beginner)

    Groups selectors; specificity is highest in list — changed behavior from :matches.

    Follow-up: :is() vs :where()?

    What is :where()?(Beginner)

    Same as :is but zero specificity — great for reset layers.

    Follow-up: Example reset with :where?

    What is specificity calculation?(Beginner)

    Inline 1000, id 100, class/attr/pseudo-class 10, type/pseudo-element 1. Trap: counting wrong on :is().

    Follow-up: Which wins: div or .btn?

    What is !important in specificity?(Beginner)

    Important declarations beat non-important regardless of specificity (within origin). Trap: two !important still use specificity.

    Follow-up: Origin order with !important?

    What is selector performance?(Beginner)

    Right-most selector matters most — .nav a is faster than a .nav-link on huge DOM? Actually .nav a scans all a — prefer class on element.

    Follow-up: Expensive selectors example?

    What is :first-child?(Beginner)

    Element that is first child of parent — trap: off-by-one if first child isn't expected type.

    Follow-up: :first-of-type difference?

    What is :nth-child?(Beginner)

    Selects by index formula — nth-child(odd) for zebra. Trap: confusing with nth-of-type.

    Follow-up: nth-child(3n+1) meaning?

    What is :empty?(Beginner)

    Selects elements with no children including text nodes whitespace-only in some browsers — test carefully.

    Follow-up: Hide empty list items?

    What is :disabled?(Beginner)

    Form controls disabled state — pair with aria-disabled for custom widgets.

    Follow-up: :disabled vs [aria-disabled]?

    What is :checked?(Beginner)

    Radio/checkbox checked — styling custom toggles. Trap: hide native input accessibly still required.

    Follow-up: Custom checkbox pattern?

    What is ::placeholder?(Beginner)

    Styles input placeholder text — contrast often fails WCAG.

    Follow-up: Placeholder vs label?

    What is ::selection?(Beginner)

    Styles highlighted text — brand polish; check contrast.

    Follow-up: Does ::selection affect readability?

    What is scoped styling?(Beginner)

    CSS Modules, shadow DOM, or BEM limit selector reach — enterprise pattern.

    Follow-up: Global selectors risk?

    What is layer @layer for selectors?(Beginner)

    Organizes cascade layers — resets lose to components without !important.

    Follow-up: @layer order?

    What is :focus-visible?(Beginner)

    Applies focus styles for keyboard not mouse — modern a11y standard.

    Follow-up: Remove outline when?

    What is attribute case sensitivity?(Beginner)

    HTML attributes case-insensitive in HTML docs; SVG differs — know your document type.

    Follow-up: Select data-testid?

    What is forgiving selector list?(Beginner)

    Invalid selectors in comma list ignored instead of killing whole rule — modern browsers.

    Follow-up: Legacy IE behavior?

    Hands-on exercise

    Mock interview drill: Answer all 25 questions out loud in 45 minutes. Record yourself explaining trade-offs, not just definitions.

    Try it yourself

    Edit the CSS panel — the preview updates live. Use DevTools Performance and Accessibility panels to validate.

    Try it yourself

    Preview
    Ready to mark this lesson complete?Track your journey across the entire course.