Style every element that is the last element of its parent with CSS

Use the CSS: last-child selector to style every <p> element that is the last child of its parent. You can try to run the following code to implement the: last-child selector

Live Demo

<!DOCTYPE html>
         p:last-of-type {
            background: orange;
      <p>This is demo text1.</p>
      <p>This is demo text2.</p>
      <p>This is demo text3.</p>

Updated on: 22-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started