Questions
6 of 25
1What are CSS combinators? How many types of CSS combinators are there?
2What is the purpose of using combinators in CSS?
3Can you list all the types of CSS combinators?
4What is the syntax for a combinator selector?
5What is the descendant combinator in CSS?
6How does the descendant combinator differ from a direct child combinator? Write an example of a descendant combinator selector. What is the impact of using multiple descendant selectors in a chain?
7How can overusing descendant combinators affect performance?
8How is the child combinator different from the descendant combinator?
9Write an example using the child combinator.
10Can the child combinator select a grandchild element? Why or why not?
11When would you prefer to use the child combinator instead of the descendant combinator?
12Can the adjacent sibling combinator select multiple elements? Write an example using the adjacent sibling combinator.
13How does the adjacent sibling combinator (+) differ from the general sibling combinator (~)? What is the general sibling combinator (~) used for?
14When would you use the general sibling combinator (~) instead of the adjacent sibling combinator (+)?
15Can the general sibling combinator (~) select elements that appear before the reference element?
16What happens if the sibling element doesn’t exist in the DOM? Can you combine multiple combinators in a single selector? Give an example.
17Can combinators be used together with pseudo-classes or pseudo-elements?
18What happens if you use a combinator between unrelated elements?
19How do combinators affect CSS inheritance and cascade?
20How would you select all <p> elements that are inside a <div> using combinators? How would you style only the direct child <li> elements inside a <ul>?
21How would you change the color of a paragraph that immediately follows a heading?
22How can you style all <span> elements that come after a specific <div>?
23Write a selector to target all <a> tags inside a <nav> but not inside a <footer>. How would you use combinators to create alternating styles between elements?
24What happens when combinators are used inside media queries? How can combinators improve maintainability in large CSS projects?
25Give a real-world example of using multiple combinators in a single rule.
06 / 25

How does the descendant combinator differ from a direct child combinator? Write an example of a descendant combinator selector. What is the impact of using multiple descendant selectors in a chain?

Descendant vs Child Combinators in CSS

The descendant combinator (space) selects all elements that are nested anywhere within a specified parent, while the direct child combinator (>) selects only elements that are immediate children of the parent.

Key Differences and Notes
  1. 1

    Descendant combinator: A B selects all B elements inside A at any depth.

  2. 2

    Child combinator: A > B selects only B elements that are direct children of A.

  3. 3

    Using multiple descendant selectors in a chain (e.g., div ul li a) increases specificity and targets elements deeply nested in the hierarchy.

  4. 4

    Excessive chaining can reduce CSS maintainability and may impact performance if overused in large DOMs.

Example: Descendant Combinator
Difficulty: 3/10
Topics: descendant combinator, child combinator, selector performance

Scenario Questions

0-2 years experience
  1. 1

    We have a navigation bar with <ul><li> items and you need to style all <a> tags inside any <li>. How would you write the selector? What would happen if you used a child combinator instead?

  2. 2

    Given HTML <div class='card'><p><span>Text</span></p></div>, you want to target the <span>. Write a selector using a descendant combinator and explain why it works.

2-5 years experience
  1. 1

    Your team added a new component inside a modal, and the existing CSS rule '.modal .content p' stopped applying. Walk me through how you would debug the selector chain and decide whether to use a descendant or child combinator.

  2. 2

    We need to style all buttons inside any form, but exclude buttons that are direct children of the form. How would you craft the selector, and what trade‑offs does this introduce for maintainability?

5-8 years experience
  1. 1

    In a large e‑commerce site, you notice that deep descendant selectors like '.catalog .category .item .price' are causing rendering slowdowns on low‑end devices. How would you assess the performance impact and refactor the CSS architecture?

  2. 2

    Your design system enforces a rule to avoid more than three levels of descendant selectors. Explain how you would enforce this rule across multiple teams and what fallback strategies you’d use if a legacy component violates it.

8+ years experience
  1. 1

    Our company is migrating a monolithic CSS codebase to a utility‑first framework. How would you handle existing complex descendant selector chains to ensure they don’t break the new system, and what long‑term strategy would you propose for selector hygiene?

  2. 2

    Cross‑team, we have a shared component library where some components rely on deep descendant selectors for theming. Discuss the architectural implications of keeping those selectors versus refactoring to CSS custom properties or BEM, considering future scalability.

Follow-up Questions

  • Can you give an example of when a descendant selector might unintentionally match more elements than you expect?
  • How does selector specificity interact with combinators?
  • What tools would you use to audit selector performance in a large stylesheet?