Article

Attribute of table in HTML


In HTML, the <table> tag is used to create tables to display data in a structured grid format. The <table> tag can contain several attributes that help in defining and customizing the behavior and appearance of the table. Here are some commonly used attributes of the <table> tag:

  1. 1. border:

    • The border attribute is used to set the border width around the table and its cells.
    • Example: <table border="1">
  2. 2. cellpadding:

    • The gap between the cell content and the cell border is specified by the cellpadding attribute.
    • Example: <table cellpadding="5">
  3. 3. cellspacing:

    • The cellspacing attribute specifies the space between table cells.
    • Example: <table cellspacing="5">
  4. 4. width:

    • The width attribute specifies the table's width.
    • Example: <table width="100%">
  5. 5. height:

    • The height attribute sets the height of the table.
    • Example: <table height="200">
  6. 6. align:

    • The align attribute aligns the table with respect to the surrounding content (left, center, right).
    • Example: <table align="center">
  7. 7. summary:

    • The summary attribute provides a brief description of the table's content for accessibility purposes.
    • Example: <table summary="Monthly sales data">
  8. 8. bordercolor:

    • The bordercolor attribute sets the color of the table border.
    • Example: <table bordercolor="#CCCCCC">
  9. 9. bgcolor:

    • The bgcolor attribute sets the background color of the table.
    • Example: <table bgcolor="#F5F5F5">

Please note that while these attributes can be used for basic formatting, it's generally recommended to use CSS (Cascading Style Sheets) for styling HTML elements, including tables. CSS provides more control and flexibility for formatting and styling tables, and it separates the design from the content, making it easier to maintain and customize the appearance of the table.