How to Merge Cells in HTML Tables
February 21, 2024
You can merge cells in an HTML table using the colspan
attribute for horizontal merging and the rowspan
attribute for vertical merging. You’ll probably also want to go past basic merging and learn about nested merges, grouping and spanning across the entire table. This post covers all this so keep reading to learn more.
What are colspan
and rowspan
in HTML?
Use the colspan
attribute in a <td>
or <th>
tag to merge cells horizontally. The colspan
value determines how many columns you should merge into a single cell. For vertical merging, apply the rowspan
attribute, which specifies the number of rows to merge.
Horizontal merging with colspan
To span a header across three columns in a table, you can apply the colspan
attribute like this:
<table border="1"> <tr> <th colspan="3">Header Spanning 3 Columns</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table>
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Vertical merging with rowspan
If you need a row label to span two rows, use the rowspan
attribute as shown below:
<table border="1"> <tr> <td rowspan="2">Row Header</td> <td>Data 1</td> </tr> <tr> <td>Data 2</td> </tr> </table>
Combining colspan
and rowspan
For more complex table structures, combine both colspan
and rowspan
attributes:
<table border="1"> <tr> <th colspan="2">Group Header</th> <th rowspan="2">Vertical Header</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
This example features a header spanning two columns and a vertical header spanning two rows, showcasing effective cell merging both horizontally and vertically.
TOC
February 21, 2024
You can merge cells in an HTML table using the colspan
attribute for horizontal merging and the rowspan
attribute for vertical merging. You’ll probably also want to go past basic merging and learn about nested merges, grouping and spanning across the entire table. This post covers all this so keep reading to learn more.
What are colspan
and rowspan
in HTML?
Use the colspan
attribute in a <td>
or <th>
tag to merge cells horizontally. The colspan
value determines how many columns you should merge into a single cell. For vertical merging, apply the rowspan
attribute, which specifies the number of rows to merge.
Horizontal merging with colspan
To span a header across three columns in a table, you can apply the colspan
attribute like this:
<table border="1"> <tr> <th colspan="3">Header Spanning 3 Columns</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table>
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Vertical merging with rowspan
If you need a row label to span two rows, use the rowspan
attribute as shown below:
<table border="1"> <tr> <td rowspan="2">Row Header</td> <td>Data 1</td> </tr> <tr> <td>Data 2</td> </tr> </table>
Combining colspan
and rowspan
For more complex table structures, combine both colspan
and rowspan
attributes:
<table border="1"> <tr> <th colspan="2">Group Header</th> <th rowspan="2">Vertical Header</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
This example features a header spanning two columns and a vertical header spanning two rows, showcasing effective cell merging both horizontally and vertically.
February 21, 2024
You can merge cells in an HTML table using the colspan
attribute for horizontal merging and the rowspan
attribute for vertical merging. You’ll probably also want to go past basic merging and learn about nested merges, grouping and spanning across the entire table. This post covers all this so keep reading to learn more.
What are colspan
and rowspan
in HTML?
Use the colspan
attribute in a <td>
or <th>
tag to merge cells horizontally. The colspan
value determines how many columns you should merge into a single cell. For vertical merging, apply the rowspan
attribute, which specifies the number of rows to merge.
Horizontal merging with colspan
To span a header across three columns in a table, you can apply the colspan
attribute like this:
<table border="1"> <tr> <th colspan="3">Header Spanning 3 Columns</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table>
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Vertical merging with rowspan
If you need a row label to span two rows, use the rowspan
attribute as shown below:
<table border="1"> <tr> <td rowspan="2">Row Header</td> <td>Data 1</td> </tr> <tr> <td>Data 2</td> </tr> </table>
Combining colspan
and rowspan
For more complex table structures, combine both colspan
and rowspan
attributes:
<table border="1"> <tr> <th colspan="2">Group Header</th> <th rowspan="2">Vertical Header</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
This example features a header spanning two columns and a vertical header spanning two rows, showcasing effective cell merging both horizontally and vertically.
What is Basedash?
What is Basedash?
What is Basedash?
Ship faster, worry less with Basedash
Ship faster, worry less with Basedash
Ship faster, worry less with Basedash
You're busy enough with product work to be weighed down building, maintaining, scoping and developing internal apps and admin panels. Forget all of that, and give your team the admin panel that you don't have to build. Launch in less time than it takes to run a standup.
You're busy enough with product work to be weighed down building, maintaining, scoping and developing internal apps and admin panels. Forget all of that, and give your team the admin panel that you don't have to build. Launch in less time than it takes to run a standup.
You're busy enough with product work to be weighed down building, maintaining, scoping and developing internal apps and admin panels. Forget all of that, and give your team the admin panel that you don't have to build. Launch in less time than it takes to run a standup.
Dashboards and charts
Edit data, create records, oversee how your product is running without the need to build or manage custom software.
USER CRM
ADMIN PANEL
SQL COMPOSER WITH AI
Related posts
Related posts
Related posts
How to Center a Table in HTML with CSS
Jeremy Sarchet
Adjusting HTML Table Column Width for Better Design
Robert Cooper
How to Link Multiple CSS Stylesheets in HTML
Robert Cooper
Mastering HTML Table Inline Styling: A Guide
Max Musing
HTML Multiple Style Attributes: A Quick Guide
Max Musing
How to Set HTML Table Width for Responsive Design
Max Musing