HTML tables can be styled using CSS (Cascading Style Sheets) to change their appearance, including their layout, font size, font family, background color, borders, and more. Here are some examples of how to style an HTML table using CSS:
- Set the font size and font family for the table and its elements:
table {
font-size: 16px;
font-family: Arial, sans-serif;
}
th, td {
font-size: 14px;
font-family: Arial, sans-serif;
}
Add background color to the table:
table {
background-color: #f2f2f2;
}
Add borders to the table and its elements:
table, th, td {
border: 1px solid black;
}
Set the width of the table and its columns:
table {
width: 100%;
}
th, td {
width: 25%;
}
Add padding and margin to the table and its elements:
table {
padding: 10px;
margin-bottom: 20px;
}
th, td {
padding: 5px;
}
These are just some examples of how you can style an HTML table using CSS. There are many more properties you can use to customize the appearance of your table.
