CSS nth-of-type(n) Selector :nth-of-type(n)

What is CSS :nth-of-type(n) Selector?

CSS :nth-of-type(n) selector matches nth number sibling of its type and whose are child elements of an parent element.


General syntax of :nth-of-type selector,

element:nth-of-type(n) {
  property: value;
  property: value;

/* match nth number sibling of its type child element */
*:nth-of-type(n) {
  property: value;
  property: value;


CSS :nth-of-type(2) selector select all 2nd sibling of its type child element.

<!DOCTYPE html>
  <title>CSS :nth-of-type(n) Selector</title>
    div :nth-of-type(2) {
      color: #FF0000;
    <span>This is first span</span>
    <span>This is second span</span>
    <span>This is third span</span>
      <li>first item</li>
      <li>second item</li>
      <li>third item</li>

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.