HTML TABLES


HTML TABLES TAG:

 HTML tables are used to present data in a tabular format, with rows and columns. They are created using the HTML "table" element, along with various other elements for defining the structure of the table and the data within it.


Here is an overview of the most commonly used elements and attributes for HTML tables:



  1. <table>: 

    This is the main element for defining a table. It creates the container for the entire table.

  2. <tr>:

     This element defines a table row. Each row contains one or more cells, defined using the "td" element.


  3. <th>:

     This element defines a header cell, typically used for column headings. The text within a "th" element is bold and centered by default.


  4. <td>: 

    This element defines a table cell, which contains the data for a particular row and column.

  5. <thead>, <tbody>, and <tfoot>: 

    These elements are used to group the content of a table into sections, such as the header section, body section, and footer section.

  6. colspan and rowspan attributes: 

    These attributes allow a cell to span multiple columns or rows, respectively.


  7. <caption>: 

    This element provides a caption or title for the table.

  8. <colgroup> and <col>: 

    These elements are used to define attributes for one or more columns, such as width or alignment.

  9. <style> and class attributes: 

    These can be used to apply CSS styles to a table or individual elements within it, such as font size, background color, borders, etc.




Here's an example of a basic HTML table:

<table>

  <caption>Sample Table</caption>

  <tr>

    <th>Column 1</th>

    <th>Column 2</th>

    <th>Column 3</th>

  </tr>

  <tr>

    <td>Row 1, Column 1</td>

    <td>Row 1, Column 2</td>

    <td>Row 1, Column 3</td>

  </tr>

  <tr>

    <td>Row 2, Column 1</td>

    <td>Row 2, Column 2</td>

    <td>Row 2, Column 3</td>

  </tr>

</table>


This will produce a table with three columns and two rows of data, with headings for each column. The "caption" element provides a title for the table.