HTML Table Colspan & Rowspan

0
6K

HTML Table Colspan and Rowspan

Colspan and rowspan are attributes used to merge cells in a table.

Colspan

  • Purpose: Merges multiple columns into a single cell.
  • Attribute: colspan
  • Example:
    HTML
    <table>
      <tr>
        <th>Product</th>
        <th>Price</th>
        <th colspan="2">Quantity</th>
      </tr>
      <tr>
        <td>Product A</td>
        <td>$100</td>
        <td>10</td>
        <td>20</td>
      </tr>
    </table>
    
    In this example, the third header cell spans two columns.

Rowspan

  • Purpose: Merges multiple rows into a single cell.
  • Attribute: rowspan
  • Example:
    HTML
    <table>
      <tr>
        <th>Product</th>
        <th>Price</th>
        <th>Quantity</th>
      </tr>
      <tr>
        <td rowspan="2">Product A</td>
        <td>$100</td>
        <td>10</td>
      </tr>
      <tr>
        <td>$200</td>
        <td>20</td>
      </tr>
    </table>
    
    In this example, the first cell in the second row spans two rows.

Important Notes

  • Header Cells: If you use colspan or rowspan with header cells, ensure that the scope attribute (col or row) is set correctly to provide accurate information for assistive technologies.
  • Cell Content: Cells that span multiple rows or columns should typically contain content that is relevant to all the merged cells.
  • Complex Tables: For complex tables with multiple levels of merging, it's often helpful to plan the structure carefully before creating the HTML.

By effectively using colspan and rowspan, you can create more efficient and visually appealing table layouts, especially for tables with repetitive or grouped data.

Like
2
Pesquisar
Categorias
Leia Mais
Physics
UCE PHYSICS SEMINAR QUESTIONS
UCE PHYSICS SEMINAR QUESTIONS
Por Expedito 2024-08-04 06:02:18 0 7K
Technology
Microsoft Outlook 2016 Step by Step
Microsoft Outlook 2016
Por Patswe 2024-08-14 21:48:58 0 5K
Technology
Creating a login form using HTML and CSS
Creating a login form using HTML and CSS is a fundamental skill in web development. Here's a...
Por tebtalks 2025-01-21 01:24:55 0 5K
Physics
UCE PHYSICS PAPER 1 2024
UCE PHYSICS PAPER 1 2024
Por Expedito 2024-08-01 16:23:47 0 7K
Chemistry
UMTA UACE UMTA CHEMISTRY PAPER 1 2024 MOCKS
UMTA UACE CHEMISTRY PAPER 1 2024 MOCKS
Por Expedito 2024-08-01 16:10:54 0 7K