<!DOCTYPE html>
<htmllang="en"><head><title>First Child</title><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><style>p:first-child {color:red;}</style></head><body><div><p>This text is selected!</p><p>This text isn't selected.</p></div><div><h2>This text isn't selected: it's not a "p".</h2><p>This text isn't selected.</p></div></body></html>
<!DOCTYPE html>
<htmllang="en"><head><title>First Child</title><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><style>p:first-of-type {color:red;}</style></head><body><div><p>This text is selected!</p><p>This text isn't selected.</p></div><div><h2>This text isn't selected: it's not a "p".</h2><p>This text isn't selected.</p></div></body></html>
Imagine a case you want to select the first child of whatever type they might be, you can use this:
<!DOCTYPE html>
<htmllang="en"><head><title>First Child</title><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><style>
.parent :first-child {color:red;}</style></head><body><divclass="parent"><p>This text is selected!</p><p>This text isn't selected.</p></div><divclass="parent"><h2>This text isn't selected: it's not a "p".</h2><p>This text isn't selected.</p></div></body></html>