CSS :first-child pseudo-element
ExampleHow to style all <p> elements that are the first child of its parent:
Try it yourself » |
Definition and Usage
The :first-child pseudo-element styles the specified selector, only if it is the first child of its parent.
Browser Support
The :first-child selector is supported in all major browsers.
Note: For :first-child to work in IE, a <!DOCTYPE> must be declared.
CSS Version
The :first-child selector was first introduced in:
CSS 2
Related Pages
CSS tutorial: CSS Pseudo classes
Try it Yourself - Examples |
ExampleStyle the first <i> element of every parent element:
Try it yourself » |
ExampleStyle all <i> element of every <p> element, where the <p> element is the first child of its parent:
Try it yourself » |
ExampleStyle the first <li> element of every list:
Try it yourself » |
ExampleStyle the first element of every <ul> element:
Try it yourself » |
Complete CSS Reference