This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Root
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:root {
/* declarations */
}
# Example
:root {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Empty
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:empty {
/* declarations */
}
# Example
:empty {
border: 1px solid red;
}
0
Try example in CodePen# Browser support
# Last-Child
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:last-child {
/* declarations */
}
# Example
span:last-child {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Only-Child
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:only-child {
/* declarations */
}
# Example
span:only-child {
background-color: gray;
color: white;
padding: 3px 6px;
}
0
Try example in CodePen# Browser support
# First-Of-Type
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:first-of-type {
/* declarations */
}
# Example
span:first-of-type {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Last-Of-Type
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:last-of-type {
/* declarations */
}
# Example
span:last-of-type {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Only-Of-Type
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:only-of-type {
/* declarations */
}
# Example
span:only-of-type {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Nth-Child
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:nth-child(an+b) {
/* declarations */
}
# Example
p:nth-child(2n+1), /* is the same as */
p:nth-child(odd) {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Nth-Last-Child
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:nth-last-child(an+b) {
/* declarations */
}
# Example
p:nth-last-child(2n+1) {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Nth-Of-Type
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:nth-of-type(an+b) {
/* declarations */
}
# Example
p:nth-of-type(2n+1) {
background-color: gray;
}
0
Try example in CodePen# Browser support
# Nth-Last-Of-Type
This pseudo-classes are so called structural pseudo-classes and selects based on the document tree but cannot be represented by other simple selectors. The index numbering starts at 1.
# Syntax
:nth-last-of-type(an+b) {
/* declarations */
}
# Example
p:nth-last-of-type(2n+1) {
background-color: gray;
}
0
Try example in CodePen