ใช้ :ลูกคนแรก pseudo class เพื่อเพิ่มรูปแบบพิเศษให้กับองค์ประกอบที่เป็นลูกคนแรกขององค์ประกอบอื่น ๆ
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อทำความเข้าใจการใช้งาน :first-child pseudo class −
<html>
<head>
<style>
div > p:first-child
{
text-indent: 25px;
}
</style>
</head>
<body>
<div>
<p>First paragraph in div. This paragraph will be indented</p>
<p>Second paragraph in div. This paragraph will not be indented</p>
</div>
<p>But it will not match the paragraph in this HTML:</p>
<div>
<h3>Heading</h3>
<p>The first paragraph inside the div. This paragraph will not be effected.</p>
</div>
</body>
</html>