The child combinator (>
) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the 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 selector, 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.
selector1 > selector2 { style properties }
span { background-color: white; } div > span { background-color: DodgerBlue; }
<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>
Specification | Status | Comment |
---|---|---|
Selectors Level 4 The definition of 'child combinator' in that specification. | Working Draft | |
Selectors Level 3 The 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. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | 12 | 1 | 7 | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors