🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #82

CSS Combinators


CSS Combinators

A combinator is something that defines the relationship between two or more selectors.

A CSS selector can contain more than one selector. Between the selectors, we can include a combinator, to create a more specific selection.

There are four different combinators in CSS:

  • Descendant combinator (space)
  • Child combinator (>)
  • Next sibling combinator (+)
  • Subsequent-sibling combinator (~)

Descendant Combinator (space)

The descendant combinator matches all elements that are descendants (children, grandchildren, etc.) of a specified element.

The following example selects all

elements inside

elements:

Example

div p {
  background-color: yellow;
}

Child Combinator (>)

The child combinator selects all elements that are direct children of a specified element.

The following example selects all

elements that are direct children of

:

Example

div > p {
  background-color: yellow;
}

Next Sibling Combinator (+)

The next sibling combinator is used to select an element that is directly after a specific element.

Sibling elements must have the same parent element.

The following example selects the first

element that immediately follows a

, and share the same parent:

Example

div + p {
  background-color: yellow;
}

Subsequent-sibling Combinator (~)

The subsequent-sibling combinator selects all elements that are next siblings of a specified element.

The following example selects all

elements that are next siblings of

, and share the same parent:

Example

div ~ p {
  background-color: yellow;
}

CSS Combinators Reference

Note: For a complete list of all CSS combinators, visit our CSS Combinators Reference.

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

CSS Combinators – FAQs

Quick answers about learning CSS Combinators in CSS.

This free note from CodingNow 2.0 explains CSS Combinators in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including CSS Combinators, is 100% free with no signup required.
With focused practice, most students grasp CSS Combinators in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now