To align table header text and table data in HTML tables, you can use CSS properties to control the alignment of content within the table cells. By default, the text in table headers and table data cells is left-aligned. However, you can modify this alignment using the "text-align" property.
The "text-align" property allows you to specify the horizontal alignment of text content within an element. It can accept various values, including "left", "right", "center", and "justify". To align table header text and table data, you will typically use the "text-align" property on the "th" (table header) and "td" (table data) elements.
Here's an example of how you can align the text in table headers to the center and the text in table data cells to the right:
html
<!DOCTYPE html>
<html>
<head>
<style>
th {
text-align: center;
}
td {
text-align: right;
}
</style>
</head>
<body>
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
</body>
</html>
In the above example, the CSS style rules target the "th" and "td" elements. The "text-align" property is set to "center" for the "th" elements, which aligns the text in the table headers to the center. The "text-align" property is set to "right" for the "td" elements, which aligns the text in the table data cells to the right.
You can also use other values for the "text-align" property to achieve different alignments. For example, setting it to "left" will align the text to the left, and setting it to "justify" will justify the text.
Additionally, you can use CSS classes or IDs to target specific table headers or data cells and apply different alignment styles as needed. This allows for more granular control over the alignment of table content.
To align table header text and table data in HTML tables, you can use the "text-align" property in CSS to control the horizontal alignment of the text. By targeting the "th" and "td" elements, you can specify different alignment styles for the table headers and table data cells.
Other recent questions and answers regarding Examination review:
- How can you style alternate rows of a table using CSS selectors?
- How can you add borders to a table using CSS?
- What is the purpose of the TR tag in HTML tables?
- How do you create a table structure in HTML using the table tag?

