HTML Questions & Answers Logo
HTML Questions & Answers Part of the Q&A Network
Q&A Logo

How can I create a table with headers that span multiple columns?

Asked on Oct 06, 2025

Answer

To create a table with headers that span multiple columns, you can use the <th> element with the colspan attribute. This attribute specifies the number of columns a header should span.
<!-- BEGIN COPY / PASTE -->
    <table>
      <tr>
        <th colspan="2">Header Spanning Two Columns</th>
      </tr>
      <tr>
        <th>Column 1</th>
        <th>Column 2</th>
      </tr>
      <tr>
        <td>Data 1</td>
        <td>Data 2</td>
      </tr>
    </table>
    <!-- END COPY / PASTE -->
Additional Comment:
  • The colspan attribute is used in the <th> element to merge columns.
  • Ensure the total column count matches across all rows for consistent table structure.
  • Use <td> for regular data cells within the table.

✅ Answered with HTML best practices.


← Back to All Questions
The Q&A Network