css

Change Last element style using CSS

You can change the style of the last HTML element of a group using CSS by using pseudo-class :last-child.

ul li:last-child {
    background: #ff0000;
    border: 1px solid #ff0000;
}

We can use :last-child pseudo-class is used to select the last element of a group of HTML elements. In the above code snippet example, we are changing the CSS style of an <li> element which is the last element of its parent.

Was this helpful?