Abakada: Back to Basics > Language References > CSS Properties > Pseudo-Classes > first-child Pseudo-class
Represents the first element among a group of sibling elements.
selector:first-child { property: value; }
property |
Any valid CSS property. |
value |
Any of the range of values available to the corresponding property. |
The :first-child pseudo-class applies styles to the first element among a group of sibling elements.
The syntax for using the :first-child pseudo-class is straightforward. A selector immediately precedes the pseudo-class.
For example, to change the background color of first-child elements on a page.
div:first-child { background-color: beige }
The following demonstrates use of the :first-child pseudo-class in an embedded stylesheet to set the style of first-child elements on a page.
:last-child( ) :nth-child( ) :nth-last-child( ) :only-child( )