A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Code Snippets > CSS > CSS3 Zebra Striping a Table Submit one!

CSS3 Zebra Striping a Table

tbody tr:nth-child(odd) {
   background-color: #ccc;
}

Subscribe to The Thread

  1. great certainly saved me some time searching

  2. Dyllon says:

    this didn’t work well for me, but the PHP one worked great.

    • CSS3 zebra striping is better solution! Why? Here is the right concept:

      1. PHP generates html as output, which should not care how the elements looks like.
      2. CSS purpose is to “care” how the elements looks like.

  3. Artem says:

    Cant understand, how it works…

  4. mike ilz says:

    @Dyllon and @Artem, here is a simple demo explaining how to use this code, and a live example of it being used.

    http://webdesignandsuch.com/2010/08/add-zebra-striping-to-a-table-with-css3/

  5. ModuLIZER says:

    Sadly… not supported by IE

  6. John says:

    Can be done with jQuery addClass.

  7. Maksvil says:

    shitty explorer not supported

  8. mcometa says:

    I bet these people saying that it isn’t working are browsers that are not supported. :D

It's Your Turn

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
--- The Management ---