Right Align content in Table Cells
To right align content in table cells using CSS, set the CSS text-align
property to right
for the table cells td
.
The CSS code to set text-align property for the table cells is shown in the following.
</>
Copy
td {
text-align: right;
}
Examples
1. Right align text in table cells
In the following example, we take a table with two columns, and three rows; and set the text alignment to right for the table cells.
index.html
</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
td {
text-align: right;
}
table, th, td {
border: 1px solid;
border-collapse: collapse;
padding: 10px;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Fruit</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apple</td>
<td>32</td>
</tr>
<tr>
<td>Banana</td>
<td>48</td>
</tr>
<tr>
<td>Cherry</td>
<td>75</td>
</tr>
</tbody>
</table>
</body>
</html>
Conclusion
In this CSS Tutorial, we learned how to use CSS text-align
property to right align content in the table cells, with examples.