Questions
3 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.
03 / 25

Can you list all the types of CSS combinators?

Difficulty: 5/10
CSS Selectors, DOM Traversal, CSS Architecture

Types of CSS Combinators

CSS combinators define the relationship between selectors, allowing you to select elements based on hierarchy or sibling relationships.

All CSS Combinators
  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

Example: Using CSS Combinators

Scenario Questions

0-2 years experience

  1. 1Imagine you have a navigation menu where you want to style only the direct list items of a '.nav-menu' class, but not the nested list items inside sub-menus. How would you write that selector, and what would happen if you accidentally used a space instead of a '>'?
  2. 2We have a form where we want to highlight an error message container (a div) that immediately follows an invalid input field. How would you target that error container using CSS without adding a new class to it?

2-5 years experience

  1. 1We're building a dynamic accordion component. When a panel is expanded, we want to style all subsequent sibling panels differently to dim them out. However, our current CSS is styling every panel in the accordion instead of just the ones after the active one. How would you debug this using sibling combinators, and what's the difference between '+' and '~' in this context?
  2. 2A developer on your team wrote a selector like '.card .header .title span'. It's causing regression issues because it's styling spans inside nested cards too. How would you refactor this selector using child combinators to make it more robust and prevent style leakage?

5-8 years experience

  1. 1In a large-scale design system, we want to implement a 'Stack' component that automatically adds spacing between its direct children, but only if there is another child preceding it (to avoid margin collapse issues). How would you design this spacing utility using combinators, and how do you ensure it doesn't break when nested components introduce their own internal margins?
  2. 2We are experiencing rendering performance bottlenecks on a highly dynamic, infinite-scroll feed page with thousands of DOM nodes. Profiling shows significant time spent in 'Recalculate Style'. We found several selectors like '.feed-container * > div ~ p'. How would you analyze the performance impact of these combinators, and how would you refactor them to optimize browser style computation?

8+ years experience

  1. 1You are migrating a legacy monolithic frontend with deeply nested CSS selectors (using heavy descendant combinators) to a modern, federated Micro-Frontend architecture. How do you establish CSS scoping boundaries and linting rules to prevent global style pollution caused by loose combinators, without forcing teams to rewrite all their legacy stylesheets overnight?
  2. 2When defining the CSS architecture for a multi-brand design system, some teams advocate for a utility-first approach (like Tailwind) while others prefer semantic CSS with complex combinators to keep the HTML clean. How do you evaluate these two paradigms in terms of long-term maintainability, browser performance at scale, and developer velocity, and what architectural guidelines would you establish?

Follow-up Questions

  • How do combinators affect the specificity calculation of a selector?
  • What are the performance implications of using deep descendant combinators in a massive DOM tree?
  • How does the browser engine evaluate selectors with combinators (right-to-left or left-to-right)?
Share

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