:last-child - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:last-child

Description

The :last-child selector selects the last element inside its parent.

:last-child is equal to :nth-last-child(1).

Example

Select the <p> element that is the last child of its parent:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:last-child {<!--  w  ww  . ja  v  a 2  s .  c om-->
    background: #ff0000;
}
</style>
</head>
<body>

<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>

<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</div>

</body>
</html>

Related Tutorials