English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Complete List of CSS Properties

CSS3 :last-Child Selector

:last-The child CSS pseudo-class represents the last child element of the parent element.

Complete CSS Selector Reference Manual

Online Example

Specify the background color of the last p element in the parent element:

!DOCTYPE html
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style> 
p:last-child
{
  background:orange;
}
</style>
</head>
<body>
<p>First paragraph.</p>
<p>Second paragraph.</p>
<p>Third paragraph.</p>
</body>
</html>
Test and see ‹/›

Definition and Usage

:last-The child selector is used to match the last child element in the parent element.

Hint: p:last-child is equivalent to p:nth-last-child(1)。

Browser Compatibility

The numbers in the table indicate the first browser version that supports this attribute.

Selector




:last-child4.09.03.53.29.6

Complete CSS Selector Reference Manual