HTML Table Colspan & Rowspan

0
2KB

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
MATIGO PHYSICS PAPER 1 2024
MATIGO UACE PHYSICS PAPER 1 2024
Por Question Bank 2024-09-05 17:26:27 0 3KB
Computer Programming
Line breaks (<br>)
The <br> tag is used to insert a single line break in your HTML content. It's an empty...
Por HTML PROGRAMMING LANGUAGE 2024-08-15 01:22:49 0 2KB
Educação
Overview of Business Information Systems (BIS)
Business Information Systems (BIS) are integrated sets of components and resources used to...
Por Business Information Systems (BIS) Course 2024-07-30 18:27:26 0 3KB
Technology
Discover How Blockchain is Revolutionizing Data Security
Stay Ahead of the Curve with the Latest in Tech! Discover How Blockchain is Revolutionizing Data...
Por ALAGAI AUGUSTEN 2024-07-23 17:21:45 0 5KB
Chemistry
S.4 CHEMISTRY WAKATA PRE MOCK QUESTIONS 2
https://acrobat.adobe.com/id/urn:aaid:sc:EU:85bd6cfc-45b5-4737-b430-d0e1fce698e9
Por Landus Mumbere Expedito 2024-07-19 23:27:53 0 3KB