:first-child CSS Pseudo Class


The CSS :first-child pseudo-class is a selector used to target and style the first child element of its parent element. It is often used in conjunction with other selectors to apply specific styling to the initial child element within a container, without affecting other child elements.

For example, you can use :first-child to apply unique styles to the first paragraph within a <div> element:

div p:first-child {
/* CSS rules for the first <p> element inside a <div> */
color: blue;
font-weight: bold;

In this example, the CSS rules will only apply to the first <p> element found within a <div> element, leaving other <p> elements within the same container unaffected.


:first-child {
  /* ... */


<p>I am the first-child so I am going to look different</p>
<p>I am the second-child, so nothing is going to change with me!</p>
<h3>I'm not a paragraph, so no change</h3>
<p>I'm a paragraph, but not the first-child.</p>
p:first-child {
color: green;
background: black;
padding: 5px;

Browser Support

The following table will show you the current browser support for the CSS :first-child pseudo class.

Edge Chrome Firefox Opera Safari
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview

Last updated by CSSPortal on: 1st October 2023