Vertical and Horizontal Headers in a table?

will_code_for_food picture will_code_for_food · Sep 8, 2011 · Viewed 18k times · Source

How would I get a table with both horizontal and vertical headers?

So e.g.

         header1 header2 header3 
header1    1        1      1
header2    2        2      2 
header3    3        3      3 

Answer

allicarn picture allicarn · Oct 25, 2013

Like @UlrichSchwarz said, you can just use <th> instead of <td> in the first column. Using scope, you can make it more semantically descriptive:

<table>
  <tr>
    <th></th>
    <th scope="col">header1</th>
    <th scope="col">header2</th>
    <th scope="col">header3</th>
  </tr>
  <tr>
    <th scope="row">header 1</th>
    <td>1</td>
    <td>1</td>
    <td>1</td>
  </tr>
  <tr>
    <th scope="row">header 2</th>
    <td>2</td>
    <td>2</td>
    <td>2</td>
  </tr>
  <tr>
    <th scope="row">header 3</th>
    <td>3</td>
    <td>3</td>
    <td>3</td>
  </tr>
</table>