CSS last-child Selector :last-child

What is CSS :last-child Selector?

CSS :last-child selector matches only last child element of its parent element.


General syntax of :last-child selector,

:last-child {
  property: value;
  property: value;

li:last-child {
  property: value;
  property: value;


CSS :last-child selector select only last <li> element of its <ul> parent element.

<!DOCTYPE html>
  <title>CSS :last-child Selector</title>
  <style type="text/css">
    li:last-child {
    <li>first item</li>
    <li>second item</li>
    <li>third item</li>
    <li>forth item</li>
    <li>fifth item</li>

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 4+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.