#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
Question 18 of 49easy

What are CSS Selector Combinators?

Understanding descendant, child, sibling combinators.

What You'll Learn

  • Combinator types
  • When to use each
  • Performance considerations

Combinator Types

CombinatorSyntaxSelects
DescendantA BAny B inside A
ChildA > BDirect children only
AdjacentA + BImmediately after A
GeneralA ~ BAny sibling after A

Examples

styles.cssCSS
/* Descendant - any nested */
nav a { color: blue; }

/* Child - direct only */
ul > li { list-style: none; }

/* Adjacent sibling - immediately after */
h1 + p { font-size: 1.2em; }

/* General sibling - any after */
h1 ~ p { margin-left: 20px; }

Real Examples

styles.cssCSS
/* Style paragraphs after headings */
h2 + p { font-weight: bold; }

/* Direct list items only */
.menu > li { display: inline-block; }

/* All siblings after checked */
input:checked ~ label { color: green; }