• Post category:HTML

Easy Steps to Create Alternate Table Row Color in HTML

HTML Table Alternate Row Color

Applying color only to the rows of odd or even numbers in a table is called HTML alternate row color.  So, if you don’t know to set alternate table row colors in HTML, don’t worry this article is for you. Use below CSS syntax to set the background color only for odd rows in the table:


  declaration list;


<table border="1px" cellpadding="10px">
   <tr align="center"><th>Name</th>
        <td>Team Leader</td>

Here, we have created a HTML table with 6 rows and 3 columns using <table>, <tr>, and <td> tags. So, the expected output:

Create alternative row color

If you want to set the background-color only for the odd rows, we need to set the background color using the below steps. Let’s create the alternative row color follow these steps:


   background-color: lightblue;

Expected Output:

html table alternate row color


  1. Here first, we selected the <tr> element then used the “nth-child()” selector and passed the “odd” value. If you want to color an even row table then you should pass the parameter value as even.
  2. Here we give odd as a parameter so, It selects all the odd numbers of <tr> elements.
  3. Inside the selection, we set “background-color” to “light blue”. You can set any background-color using coloname, hexcode, RGB(), rgba(), etc.
  4. See, the above output our alternative row background color is set perfectly.

Leave a Reply