Computer >> Computer tutorials >  >> Programming >> HTML

How to set horizontal header for a table?


Tables in HTML can have horizontal as well as the vertical header. For the horizontal header, you need to set all <th> inside a single <tr> tag i.e. row, that will be the topmost.

How to set horizontal header for a table?

Example

You can try to run the following code to set a horizontal header for a table

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
            width: 100px;
            height: 50px;
         }
      </style>
   </head>

   <body>
      <h1>Employee Details</h1>
      <table>
         <tr>
            <th>Name</th>
            <th>Age</th>
            <th>Technology</th>
         </tr>
         <tr>
            <td>Amit</td>
            <td>27</td>
            <td>Database</td>
         </tr>
         <tr>
            <td>Sachin</td>
            <td>34</td>
            <td>Marketing</td>
         </tr>
      </table>
   </body>
</html>

Output

How to set horizontal header for a table?