The child combinator (>
) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first.
/* List items that are children of the "my-things" list */
ul.my-things > li {
margin: 2em;
}
Elements matched by the second selector must be the immediate children of the elements matched by the first selector. This is stricter than the descendant combinator, which matches all elements matched by the second selector for which there exists an ancestor element matched by the first selector, regardless of the number of "hops" up the DOM.
Syntax
selector1 > selector2 { style properties }
Examples
CSS
span {
background-color: white;
}
div > span {
background-color: DodgerBlue;
}
HTML
<div>
<span>Span #1, in the div.
<span>Span #2, in the span that's in the div.</span>
</span>
</div>
<span>Span #3, not in the div at all.</span>
Result
Specifications
Specification | Status | Comment |
---|---|---|
Selectors Level 4The definition of 'child combinator' in that specification. | Working Draft | |
Selectors Level 3The definition of 'child combinators' in that specification. | Recommendation | No change. |
CSS Level 2 (Revision 1)The definition of 'child selectors' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Child combinator (A > B )
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 7 |
Opera
Full support 4 |
Safari
Full support 1 |
WebView Android
Full support ≤37 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
See also
Child combinator by Mozilla Contributors is licensed under CC-BY-SA 2.5.