HTML Table Colspan & Rowspan

0
2K

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
Căutare
Categorii
Citeste mai mult
Technology
Executive Information Systems (EIS)
Executive Information Systems (EIS) are specialized information systems designed to support the...
By Business Information Systems (BIS) Course 2024-08-01 17:01:05 0 3K
Business
Running a Successful Business
Beyond Profits to Building a Strong Foundation In the world of business, success is often...
By ALAGAI AUGUSTEN 2024-08-03 15:49:40 0 3K
Computer Programming
Element-specific attributes (alt for images, href for links)
While global attributes can be applied to any HTML element, some attributes are specific to...
By HTML PROGRAMMING LANGUAGE 2024-08-15 01:47:04 0 2K
Educaţie
The Kansas-Nebraska Act: A Fiery Catalyst for Conflict - Civil War
The Kansas-Nebraska Act, passed by Congress in 1854, was a pivotal piece of legislation that...
By Dieme Samson 2024-09-12 03:05:13 0 3K
Chemistry
UCE CHEMISTRY JJEB 2024
UCE CHEMISTRY JJEB 2024
By Landus Mumbere Expedito 2024-08-12 09:34:13 0 3K