<section>
    <p>First 'p' element of its type</p>
    <div>First 'div' element of its type</div>
    <p>Second 'p' element of its type</p>
    <p>Third 'p' element of its type</p>
    <div>Second 'div' element of its type</div>
    <div>Third 'div' element of its type</div>
</section>
/* Selects the second <p> element of its type among <section> children */
section p:nth-of-type(2) {
    background-color: yellowgreen;
}

/* Selects the second <div> element of its type among <section> children */
section div:nth-of-type(2) {
    background-color: orange;
}
Rendered Output
/* Positive integers: select the nth <li> element of its type under the same parent */
li:nth-of-type(1)  /* counts only the <li> elements under the same parent and selects the first one */
li:nth-of-type(7)  /* counts only the <li> elements under the same parent and selects the seventh one */

/* Keywords: odd / even */
li:nth-of-type(odd)  /* counts only the <li> elements under the same parent and selects the odd ones (1, 3, 5, ...) */
li:nth-of-type(even) /* counts only the <li> elements under the same parent and selects the even ones (2, 4, 6, ...) */

/* Formulas: An+B */
li:nth-of-type(2n)  /* counts only the <li> elements under the same parent and selects every 2nd element */
li:nth-of-type(3n)  /* counts only the <li> elements under the same parent and selects every 3rd element */

li:nth-of-type(3n+1) /* counts only the <li> elements under the same parent and selects every 3rd element plus 1 */
li:nth-of-type(3n-1) /* counts only the <li> elements under the same parent and selects every 3rd element minus 1 */
:nth-of-type(index | odd | even | an+b) {
    /* ... */
}
<section>
    <p>First 'p' element of its type</p>
    <div>First 'div' element of its type</div>
    <p>Second 'p' element of its type</p>
</section>
div:nth-of-type(1) {
    background-color: yellowgreen;
}
p:nth-of-type(2) {
    background-color: orange;
}
Rendered Output
<section>
    <p>First 'p' element of its type</p>
    <div>First 'div' element of its type</div>
    <p>Second 'p' element of its type</p>
    <p>Third 'p' element of its type</p>
    <div>Second 'div' element of its type</div>
    <div>Third 'div' element of its type</div>
</section>
div:nth-of-type(even) {
    background-color: yellowgreen;
}
p:nth-of-type(odd) {
    background-color: orange;
}
Rendered Output
:nth-of-type(5n)
/*
 * 0 [=5×0], 5 [=5×1], 10 [=5×2], 15 [=5×3], ... positions in the list.
 * Indexing starts at 1, so the 0th element does not exist.
 * Therefore, elements at positions 5, 10, 15, ... are selected.
 * In summary, 5n selects every 5th element of the same tag type.
*/

:nth-of-type(5n-1)
/*
 * -1 [=5×0-1], 4 [=5×1-1], 9 [=5×2-1], 14 [=5×3-1], ... positions in the list.
 * Indexing starts at 1, so the -1st element does not exist.
 * Therefore, elements at positions 4, 9, 14, ... are selected.
 * In summary, 5n-1 selects one element before each multiple of 5 of the same tag type.
*/

:nth-of-type(5n+1)
/*
 * 1 [=5×0+1], 6 [=5×1+1], 11 [=5×2+1], 16 [=5×3+1], ... positions in the list.
 * Indexing starts at 1.
 * Therefore, elements at positions 1, 6, 11, 16, ... are selected.
 * In summary, 5n+1 selects one element after each multiple of 5 of the same tag type.
*/

:nth-of-type(n)
/*
 * 0 [0], 1 [1], 2 [2], 3 [3], ... positions in the list.
 * Indexing starts at 1, so the 0th element does not exist.
 * Therefore, elements at positions 1, 2, 3, ... are selected.
 * In summary, n selects all elements of the same tag type.
*/
<ol>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
</ol>   
ol {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    gap: 7px;
}
ol li {
    aspect-ratio: 1/0.5;
    border: 1px solid red;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
}
ol li:nth-of-type(5n-1) { /* Selects elements one before multiples of 5 */
    background-color: yellowgreen;
}
Rendered Output
<style>
    .red-item:nth-of-type(2) {
        color: red;
        font-weight: bold;
    }
</style>
<ol>
    <li>li</li>
    <li class="red-item">Matched element</li>
    <li class="red-item">Expected match but not selected</li>
</ol>
<!--
    * Did you try to select the second element of type '.red-item'?
    * If so, that is incorrect.
    *
    * .red-item:nth-of-type(2) can be broken down as follows:
    * => .red-item: selects elements with a class attribute value of 'red-item' whose tag name is <li>.
    * => The "same tag type" refers to the tag name type.
    * => The element type here is <li>.
    * => The second <li> element is selected only if it has the class 'red-item'.
    * => Therefore, <li class="red-item">Matched element</li> is selected.
-->
Rendered Output