CSS first-of-type Selector :first-of-type

What is CSS :first-of-type Selector?

CSS :first-of-type selector matches first sibling of its type in child elements of an parent element.


General syntax of :first-of-type selector,

element:first-of-type {
  property: value;
  property: value;

/* match all first sibling of its type child element */
*:first-of-type {
  property: value;
  property: value;


CSS :first-of-type selector select all first sibling of its type child element.

<!DOCTYPE html>
  <title>CSS :first-of-type Selector</title>
    div :first-of-type {
      color: #FF0000;
    <span>This is first span</span>
    <span>This is second span</span>
      <li>first item</li>
      <li>second item</li>
    <p>First Paragraph</p>
    <p>Second Paragraph</p> 

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 4+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.