This page is part of the CSS3.info CSS selectors test. See more info on CSS3 selectors.
div :nth-child(1) {
}
<div>
<div>Does this element match?</div>
</div>
The CSS selector should match the marked element, because it is the first and only child of the outer div element
div :nth-child(0n+1) {
}
<div>
<div>Does this element match?</div>
</div>
The CSS selector should match the marked element, because it is the first and only child of the outer div element
div :nth-child(1) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div></div>
<div></div>
</div>
The CSS selector should match the marked element, because it is the first child of the outer div element
div :nth-child(0n+1) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div></div>
<div></div>
</div>
The CSS selector should match the marked element, because it is the first child of the outer div element
div :nth-child(2) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div></div>
</div>
The CSS selector should match the marked element, because it is the second child of the outer div element
div :nth-child(0n+2) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div></div>
</div>
The CSS selector should match the marked element, because it is the second child of the outer div element
div :nth-child(1n) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element should match
div :nth-child(n) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element should match
div :nth-child(n+1) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element should match
div :nth-child(1n+1) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element should match
div :nth-child(n+2) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element starting from the second should match
div :nth-child(1n+2) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every element starting from the second should match
div :nth-child(even) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every even element should match
div :nth-child(odd) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should match all marked elements, because every odd element should match
div :nth-child(2n) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every even element should match
div :nth-child(2n-1) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should match all marked elements, because every odd element should match
div :nth-child(2n+0) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every even element should match
div :nth-child(2n+1) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should match all marked elements, because every odd element should match
div :nth-child(2n+2) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every even element should match
div :nth-child(3n+1) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should match all marked elements, because every third element should match
div :nth-child(-n+2) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div></div>
<div></div>
</div>
The CSS selector should match all marked elements, because the first two elements should match
div :nth-child(0) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should match no elements at all
div :nth-child(0n+0) {
}
<div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should match no elements at all
div :nth-child(1) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should only match the first element
div :nth-child(0n+1) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should only match the first element
div :nth-child(2) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should only match the second element
div :nth-child(0n+2) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because it should only match the second element
div :nth-child(n+2) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div></div>
<div></div>
</div>
The CSS selector should not match the marked element, because every element starting from the second should match
div :nth-child(1n+2) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div></div>
<div></div>
</div>
The CSS selector should not match the marked element, because every element starting from the second should match
div :nth-child(even) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should not match the marked elements, because every even element should match
div :nth-child(odd) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because every odd element should match
div :nth-child(2n) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should not match the marked elements, because every even element should match
div :nth-child(2n-1) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because every odd element should match
div :nth-child(2n+0) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should not match the marked elements, because every even element should match
div :nth-child(2n+1) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because every odd element should match
div :nth-child(2n+2) {
}
<div>
<div>Does this element match?</div>
<div></div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should not match the marked elements, because every even element should match
div :nth-child(3n+1) {
}
<div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
<div></div>
</div>
The CSS selector should not match the marked elements, because every third element should match
div :nth-child(-n+2) {
}
<div>
<div></div>
<div></div>
<div>Does this element match?</div>
<div>Does this element match?</div>
</div>
The CSS selector should not match the marked elements, because only the first two should match
div :nth-child(1) {
}
<div>
<div id='insertBefore'></div>
</div>
var ib = document.getElementById('insertBefore');
ib.parentElement.insertBefore(document.createElement("div"), ib);
The CSS selector should match the div element that is inserted by the Javascript code.
div :nth-child(1) {
}
<div>
<div id='insertBefore'></div>
</div>
var ib = document.getElementById('insertBefore');
ib.parentElement.insertBefore(document.createElement("div"), ib);
The original div element should not be a match for the :nth-child() selector.