CSS TABLE SIZE(WIDTH AND HEIGHT)

CSS Table Size (Width and Height)

You can control a table’s width and height in CSS using the width and height properties.

table {
  width: 80%;
  height: 300px;
}

Example

<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Ali</td>
    <td>20</td>
  </tr>
</table>
table {
  width: 500px;
  height: 200px;
  border-collapse: collapse;
}

th, td {
  border: 1px solid black;
  padding: 10px;
}

Common CSS properties

Property Purpose Example
width Sets table width width: 500px;
height Sets table height height: 200px;
padding Adds space inside cells padding: 10px;
border-spacing Controls space between cells border-spacing: 5px;
border-collapse Combines cell borders border-collapse: collapse;

Tip: For responsive tables, you can use:

table {
  width: 100%;
}

This makes the table expand to the width of its container.

Comments