How to create zebra stripes on the html table without using javascript generation and unpaired or odd classes?

advertisements

I want to zebra-stripe a html table without using any js stuff or writing server-side code to generate even/odd classes for table rows. Is it ever possible to do using raw css?


It is possible, with CSS3 selectors:

tr:nth-child(even) {
  background-color: red;
}

tr:nth-child(odd) {
  background-color: white;
}

According to caniuse.com, every browser supports it now.