HTML Tables Attributes

1. border

Specifies the width of the table's border.

Example:

<table border="2">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

2. cellpadding

Defines the space between the content of a cell and its border.

Example:

<table border="1" cellpadding="10">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

3. cellspacing

Specifies the space between individual table cells.

Example:

<table border="1" cellspacing="5">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

4. width

Sets the width of the table (can use percentage or fixed values in pixels).

Example:

<table border="1" width="50%">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

5. height

Sets the height of the table (can use percentage or fixed values in pixels).

Example:

<table border="1" height="100">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

6. align (Deprecated in HTML5)

Specifies the alignment of the table relative to the surrounding content.

  • Values: left, center, right.

Example:

<table border="1" align="center">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

7. bgcolor (Deprecated in HTML5)

Sets the background color of the table.

Example:

<table border="1" bgcolor="lightblue">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

8. summary (Obsolete)

Provides a description of the table's purpose for screen readers.

Example:

<table border="1" summary="This table lists product names and prices">
    <tr>
      <td>Product</td>
      <td>Price</td>
    </tr>
  </table>

9. frame

Specifies which sides of the table's border should be visible.

  • Values: void, above, below, hsides, vsides, lhs, rhs, box, border.

Example:

<table border="1" frame="box">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

10. rules

Determines how the internal gridlines of the table should appear.

  • Values: none, groups, rows, cols, all.

Example:

<table border="1" rules="rows">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

11. bordercolor (Deprecated in HTML5)

Defines the color of the table's border.

Example:

<table border="1" bordercolor="red">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

Modern Approach:

While some of these attributes (e.g., align, bgcolor, bordercolor) are deprecated in HTML5, you can achieve similar effects using CSS.

Example using CSS:

<table style="border: 2px solid black; width: 100%; height: 200px; border-spacing: 10px;">
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
    </tr>
  </table>

Comments

Popular posts from this blog

Introduction to Computer

History of Computer

Computer Generation