Table IN HTML

The <table> tag in HTML is used to create structured grids for displaying data in rows and columns. It's comprised of nested elements like <tr> for rows, <td> for data cells, and <th> for headers. Tables offer a systematic way to organize information, commonly used in displaying datasets, schedules, or product listings on web pages. With additional attributes and CSS styling, tables can be customized for better readability and presentation.

Basic Structure :

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table> </body> </html>

Attributes like 'border', 'cellpadding', and 'cellspacing' can be added to adjust the table appearance. Additionally, attributes like colspan and rowspan control cell span across columns and rows respectively. CSS can further enhance table styling and responsiveness.

  • Example of Table in HTML :
  • Example 1 :

    <!DOCTYPE html> <html> <head> <style> table, th, td { border: 2px solid black; } </style> </head> <body> <table> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table> </body> </html>

    Output :

    Month Savings
    January $100
    February $80

    Example-2:Table with color and border:

    <!DOCTYPE html> <html> <head> <title>Table</title></head> <style type="text/css"> table.col { background-color: rgba(214, 234, 248 ); border: 1px solid black; color:black; } th.coll { background-color: rgba(133, 193, 233); } <body> <p align="Center"> <Table class="col"> <tr align="Center"> <th class="coll">PBA INSTITUTE</th> <th class="coll">Course FEES</th> </tr> <tr align="Center"> <td>JAVA</td> <td>6000</td> </tr> <tr align="Center"> <td>WEB DESIGN</td> <td>5000</td> </tr> </table> </body> </html>

    Output :

    Table

    PBA INSTITUTE COURSE FEES
    JAVA 6000
    WEB DESIGN 5000
  • Conclusion :
  • .