Questions
1 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.
01 / 25

What are CSS combinators? How many types of CSS combinators are there?

Difficulty: 5/10
combinators, selector specificity, performance

CSS Combinators

CSS combinators are symbols that explain the relationship between selectors. They allow you to target elements based on their relationship to other elements in the DOM hierarchy.

Types of CSS Combinators
  1. 1

    Descendant combinator (space) – selects all elements that are descendants of a specified element. Example: div p selects all <p> inside <div>.

  2. 2

    Child combinator (>) – selects elements that are direct children of a specified element. Example: div > p selects <p> directly inside <div>.

  3. 3

    Adjacent sibling combinator (+) – selects an element that is immediately preceded by a specified sibling. Example: h1 + p selects the first <p> after an <h1>.

  4. 4

    General sibling combinator (~) – selects all elements that are siblings of a specified element. Example: h1 ~ p selects all <p> siblings after <h1>.

Example: Using Different Combinators

Scenario Questions

0-2 years experience

  1. 1You need to style only the direct child <li> elements inside a <ul class="menu">. Which combinator would you use and how would you write the selector?
  2. 2If you have a <div> with several <p> elements and you want to style any <p> that follows another <p> directly, which combinator helps you achieve that?
  3. 3What would change if you used a descendant combinator instead of the child combinator in the first scenario?

2-5 years experience

  1. 1A form contains inputs that can get an 'error' class. We need to disable the submit button only when an error input exists anywhere in the same form. How would you rewrite the selector using combinators to target the button correctly?
  2. 2A style meant for navigation links inside a header is also affecting links in the footer. Explain how you would narrow the selector with combinators to affect only the header links.
  3. 3Your team added a utility class that uses the adjacent sibling (+) combinator, but it fails when there are whitespace text nodes between elements. What might be causing this and how would you fix it?

5-8 years experience

  1. 1Our design system has deep component hierarchies, and we notice descendant combinators causing performance regressions on large pages. How would you assess the impact and refactor selectors to improve rendering speed?
  2. 2We want to ban the general sibling (~) combinator because it leads to unpredictable styling with dynamic content. How would you redesign the component CSS to avoid it while keeping layout flexibility?
  3. 3When migrating a legacy codebase to CSS‑in‑JS, you need to translate complex selector chains that include child and descendant combinators. What strategy ensures identical behavior and maintainability after the migration?

8+ years experience

  1. 1Multiple product front‑ends have used different combinator patterns, causing selector conflicts and specificity wars. As a staff engineer, how would you define a cross‑team CSS architecture policy around combinator usage to minimize conflicts and support long‑term scalability?
  2. 2We are moving from a monolithic stylesheet to a modular, token‑driven system and want to replace deep descendant selectors with explicit combinators for better maintainability. What process and tooling would you put in place to audit, refactor, and prevent regressions across all teams?
  3. 3A feature flag toggles insertion of new DOM elements that affect existing sibling combinator selectors. How would you design the CSS and the flag implementation to avoid breaking styles when the flag is turned on or off in production?

Follow-up Questions

  • Can you write the exact selector you would use for that case?
  • What trade‑offs exist between using a descendant versus a child combinator?
  • How would you verify that your selector only matches the intended elements?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.