Question
Answer and Explanation
To bold the headers of a table, you can use HTML and CSS. Here's how you can achieve this:
1. Using HTML `
The most semantically correct way to define table headers is by using the <th>
tag. Browsers usually render these tags in bold by default. If you don't see bold headers, it is likely a css rule is overwriting them. Here’s an example table structure using <th>
:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</tbody>
</table>
2. Using CSS to force bold:
If, for some reason, your headers are not displaying as bold you can use css. To apply bold to table headers using CSS, you can use the font-weight
property.
Here's how you can apply bold to all <th>
elements:
<style>
th {
font-weight: bold;
}
</style>
Alternatively, you can be more specific if you want to target headers in specific tables using a class or ID on the <table>
element:
<style>
.my-table th {
font-weight: bold;
}
</style>
In this case, you would need to add a class to your table like so: <table class="my-table">
By using <th>
tags or, if required, adding a css rule to use font-weight: bold;
on the table header elements, you can easily bold your table headers. This makes them visually distinct and improves readability.