← TechnologyThe essentials of

:nth-child() counts the position among all elemental children

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 13:48. This is not editorial approval.

In a few sentences

In brief

Mixed tags affect the element number.

Useful to know

:nth-child() selects by position among the elemental children of one parent. Counting starts at 1 and includes the different types of elements, not just those with the same tag. [1]

If the container starts with h2, followed by three p, the first paragraph is the second child. Therefore, p:nth-child(2) will select it. For counting by type of element there is :nth-of-type(). In alternating rows, consider what happens after adding a title or hidden line: the position selector follows the document structure, not the meaning of the content.

Sources

For further detail and to check the information:

  1. [1] MDN — :nth-child ↗