How to specify the number of columns a table cell should span in HTML?


Use the colspan attribute to set the number of columns a table cell should span. You can try to run the following code to implement colspan attribute −

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <h2>Total Marks</h2>
      <table>
         <th>Subject</th>
         <th>Marks</th>
         <tr>
            <td>Maths</td>
            <td>300</td>
         </tr>
         <tr>
            <td>Java</td>
            <td>450</td>
         </tr>
         <tr>
            <td colspan="2">Total Marks: 750</td>
         </tr>
      </table>
   </body>
</html>

Updated on: 03-Mar-2020

566 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements