You can to set different properties of an HTML table using CSS.
You can set following properties of a table − −
boarder : To specify table borders in CSS
border-collapse : To specify whether the table borders should be collapsed into a single border
padding : To specify the space between the border and the content in a table
width and height : To specify whether the table are defined by the width and height properties.
text-align : To specify the horizontal alignment (like left, right, or center) of the content
color : To specify table color in CSS.
background-color : To specify table background color in CSS.
You can learn how to create a table using HTML. HTMl Create Table
Example : CSS - Table
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th
{
height: 30px;
text-align: left;
vertical-align: top;
padding: 15px;
background-color: #4CAF50;
color: white;
border:3px solid Yellow;
}
td {
border:3px solid blue;
text-align: right;
}
tr:hover {background-color: red;}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>Rock</td>
<td>23</td>
</tr>
<tr>
<td>Selina</td>
<td>Jack</td>
<td>29</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>12</td>
</tr>
</table>
</body>
</html>
When the above code is compiled , it produces the following result.
Result
Firstname |
Lastname |
Age |
John |
Rock |
23 |
Selina |
Jack |
29 |
Sam |
Watson |
12 |