<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 last <p> element of its type among <section> children */
section p:last-of-type {
    background-color: yellowgreen;
}

/* Selects the last <div> element of its type among <section> children */
section div:last-of-type {
    background-color: orange;
}
Rendered Output
:last-of-type {
    /* ... */
}
<article>
    <h2>Heading Element</h2>
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
</article>
article p:last-of-type {
    background-color: yellowgreen;
}
Rendered Output
<article>
    <div>This 'div' is the first one.</div>
    <div>This <span>nested 'span' is both the first and the last one.</span>!</div>
    <div>
        This <em>nested 'em' is the first one.</em>, but this <em>nested 'em' is the last one.</em>!
    </div>
    <div>This <span>nested 'span' is styled. It is both the first and the last one.</span>!</div>
    <p>This 'p' is both the first and the last one.</p>
    <div>This 'div' is the last one.</div>
</article>
article :last-of-type { /* Same as article *:last-of-type과 동일 */
    background-color: yellowgreen;
}
Rendered Output
<style>
    .red-item:last-of-type {
        color: red;
        font-weight: bold;
    }
</style>
<ol>
    <li class="red-item">li</li>
    <li class="red-item">Expected to match, but it doesn't</li>
    <li>li</li>
</ol>
<!--
    * Did it select the last element with the .red-item class?
    * If so, that is incorrect.
    *
    * :last-of-type selects the last element of a given tag type among its siblings.
    *
    * .red-item:last-of-type can be broken down as follows:
    * => .red-item: targets elements with the class value 'red-item'.
    * => Specific type refers to the tag name.
    * => In this case, the <li> element is the specific type.
    * => The last <li> of this type must have the class 'red-item' to be selected.
    * => Therefore, none of the elements above match.
-->
Rendered Output No elements are matched by the .red-item:last-of-type selector.