CSS – Styling Every Other Element

There are a lot of times where you will want to automatically style every other element slightly differently, for example, in a table, to make it more legible. Here’s how.

tr {

tr:nth-child(odd) {

The :nth-child(odd) property will target every other item of the element you have selected. Here is a working sample.

See the Pen CSS – Every Other Item Style by Nicholas Coughlin (@nicholascoughlin) on CodePen.