CSS :last-child Pseudo-class
Example
Specify a background color for the <p> element that is the last child of its parent. Also specify a background color for the <li> element that is the last child of its parent:
p:last-child {
background-color: yellow;
}
li:last-child {
background-color: yellow;
}
Try it Yourself »
Definition and Usage
The :last-child
pseudo-class
matches any element that is the last child of its parent.
Tip: p:last-child is equal to p:nth-last-child(1).
Version: | CSS3 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:last-child | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS Syntax
Related Pages
CSS Reference: :last-of-type