:first-of-type - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:first-of-type

Description

The :first-of-type selector selects element that is the first child of a particular type from its parent.

It is the same as :nth-of-type(1).

Example

Select the first <p> element of its parent:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:first-of-type {
    background: red;
}
</style><!--  w  w  w .jav  a  2 s  . c  o  m-->
</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