How to display only the first two elements from ten same elements

You can css

ul li:nth-child(n+3) {
    display: none;
}

It’ll not show 3rd and up.