Table of Contents
INTRODUCTION
Combinators are used to define the relation between selectors. Hence an combinator is placed between two selectors. Based on the relation we can select elements to which CSS rule is applied. There are various types of Combinators which establishes different relationships between elements. Below is list of all Combinator available in CSS.
- Descendant Combinator (Space)
- Child Combinator (>)
- Next Sibling Combinator (+) (Adjacent Sibling Combinator)
- Subsequent Sibling Combinator (~)

Descendant Combinator
The descendant combinator is used to select elements that are nested inside another element at any level of depth. It doesn’t matter how deep the second element is; as long as it exists somewhere within the first element, it will be selected. Descendant Combinator is represented by single space(" ") between two selectors.
This combinator is very useful when you want to apply styles based on a general ancestor context, without requiring the structure to be strictly direct or specific.
For example, div p will target every <p> element inside a <div>, whether it’s a direct child or deeply nested.
Syntax:
selector1 selector2{
CSS RULE;
}
Example: In the below example the <p> element which is inside <div> and inside <span> both are descendants of <div>. Hence the CSS rule is applied to both.
div p {
color: blue;
}
<p> This paragraph is outside div. </p>
<div>
<p> This paragraph is inside div. </p>
<span>
<p> This paragraph is inside span with div as ancestor. </p>
</span>
</div>
This paragraph is outside div.
This paragraph is inside div.
This paragraph is inside span with div as ancestor.
Child Combinator
Child Combinator is represented by >. It selects only the elements that are direct children of a specific parent. This combinator is ideal for applying styles in a structured and controlled manner, especially in layouts and menus, where child elements must be styled differently from nested ones.
For instance, ul > li will select only those <li> elements that are immediate children of a <ul>, and not any <li> nested deeper inside another tag.
Syntax:
selector1 > selector2{
CSS RULE;
}
Example: In the above example the first <p> element which is inside <div> is direct child of <div>. Hence the CSS rule is applied to only first <p>. The <p> inside <span> is not direct child of <div>, so no CSS rule is applied to it.
div > p {
color: blue;
}
<p> This is paragraph which is not child of div </p>
<div>
<p> This is paragraph which is direct child of div </p>
<span>
<p> This is paragraph inside span and not direct child of div </p>
</span>
</div>
This is paragraph which is not child of div.
This is paragraph which is direct child of div.
This is paragraph inside span and not direct child of div.
Adjacent/Next Sibling Combinators
The adjacent sibling combinator selects an element that comes immediately after another element and shares the same parent. This combinator is represented by +
It’s useful when you want to change the style of an element based on what comes right before it. This can be applied for styling notifications, headings followed by descriptions, or lists with dynamic spacing, providing very specific and contextual styling.
For example, h2 + p selects the first <p> tag that appears right after an <h2> tag.
Syntax:
selector1 + selector2{
CSS RULE;
}
Example: In the above example the <h2> and first <p> element are both siblings of <div> and <p> commes immediately after <h2>. This satisfy condition of Next-sibling combinator and CSS rule is applied to first <p>.
h2 + p {
color: blue;
}
<p> This paragraph is not child of div. </p>
<div>
<h2> This is h2 heading </h2>
<p> This paragraph is sibling of h2 and comes immediately after h2. </p>
<span>
<p> This paragraph is inside span and not sibling of h2. </p>
</span>
<p> This paragraph is other sibling of h2 and does not comes immediately after h2. </p>
</div>
This paragraph is not child of div.
This is h2 heading
This paragraph is sibling of h2 and comes immediately after h2.
This paragraph is inside span and not sibling of h2.
This paragraph is other sibling of h2 and does not comes immediately after h2.
Subsequent Sibling Combinators
Subsequent Sibling Combinator is represented by (~). This combinator selects all sibling elements that follow a specific element and share the same parent, not just the immediate one.
This is useful when the order of elements matters and you want to apply styles to a group of elements that follow a certain one, like making all paragraphs after a certain heading appear in a different style or layout.
For example, h2 ~ p will select every <p> element that comes after an <h2> under the same parent, regardless of what elements are in between.
Syntax:
selector1 ~ selector2{
CSS RULE;
}
Example:
h2 ~ p {
color: blue;
}
<p> This paragraph is not child of div. </p>
<div>
<h2> This is h2 heading </h2>
<p> This paragraph is sibling of h2 and comes after h2. </p>
<span>
<p> This paragraph is inside span and not sibling of h2. </p>
</span>
<p> This paragraph is other sibling of h2 and comes after h1 not immediately. </p>
</div>
This paragraph is not child of div.
This is h2 heading
This paragraph is sibling of h1 and comes after h2.
This paragraph is inside span and not sibling of h2.
This paragraph is sibling of h2 and comes after h2 not immediately.
In the above exapmle we want to select all <p> element which comes after <h1> and are siblings of it. So we use Subsequent Siblings Combinator (h1 ~ p).
Frequently Asked Questions (FAQ)
What is the difference between descendant and child combinators in CSS?
1. Descendant Combinator
It is denoted by (space). Matches any level of nesting inside the parent. Can be a direct or indirect descendant (grandchild, great-grandchild, etc.)
2. Child Combinator
It is denoted by (>). Matches only direct children of the parent.
What does the > selector mean in CSS?
parent > child {
/* CSS rules */
}
What Does the ~ (Tilde) Selector Mean in CSS?
Example: It Selects every B element that is a sibling of A and comes after A in the HTML structure.
A ~ B {
/* styles for B */
}
What is the difference between CSS selectors and combinators?
Feature | CSS Selectors | CSS Combinators |
---|---|---|
Purpose | Select specific HTML elements to style | Define relationships between selected elements |
Targets | Individual elements (by tag, class, ID, etc.) | Elements based on hierarchy or position in the DOM |
Examples | p , .box , #header ,
[type="text"]
|
div > p , h1 + p , ul ~ li ,
div p
|
Symbols Used | No symbol (just pattern) | (space), > , + ,
~
|
Used With | Tags, classes, IDs, attributes, etc. | Used between two selectors |
Can Be Combined? | ✅ Yes | ✅ Yes (between selectors) |
What Does the + (Plus Sign) CSS Selector Mean?
Example: Selects the first B element that immediately follows A, and both share the same parent.
A + B {
/* styles for B */
}
Can I combine multiple combinators in one CSS rule?
Example: This example Targets a <span> that is:
- Immediately after a <p> (+),
- That <p> is inside a <div> (descendant) and
- That <div> is a direct child of a <section> (>)
section > div p + span {
color: red;
}