Question
Is there a built-in Twitter Bootstrap class for aligning text within table cells? For example, how can I right-align a table header and a currency total?
<th class="align-right">Total</th>
<td class="align-right">$1,000,000.00</td>
Short Answer
Bootstrap provides text-alignment utility classes that can be applied directly to <th> and <td> elements. You will learn which class to use in Bootstrap 3, 4, and 5, why numeric columns are normally right-aligned, and how to choose a class that matches your project’s Bootstrap version.
Concept
Text alignment controls where inline content, such as words and numbers, appears inside its container. In an HTML table, the container is usually a table header cell (<th>) or data cell (<td>).
Right-aligning numbers makes columns easier to scan because digits with the same place value line up visually. This is especially useful for prices, totals, percentages, account balances, and quantities.
Bootstrap exposes common CSS rules through utility classes, so you do not need to create a custom class for a simple alignment rule.
The correct class depends on your Bootstrap version:
- Bootstrap 3 and 4: use
.text-right. - Bootstrap 5: use
.text-end.
Bootstrap 5 uses logical alignment names: start and end. In a left-to-right language such as English, end means right. This also lets layouts adapt better to right-to-left languages.
Mental Model
Think of every table cell as a small box with a line of text inside it.
- Left alignment places the text against the box’s left wall.
- Center alignment places the text in the middle of the box.
- Right alignment places the text against the box’s right wall.
For a column of money, putting every value against the right wall makes the decimal points and final digits appear in a consistent vertical area. That makes comparison faster.
Syntax and Examples
Use the alignment utility directly on the table cell.
Bootstrap 5
<table class="table">
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col" class="text-end">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Annual subscription</td>
<td class="text-end">$1,000,000.00</td>
</tr>
</tbody>
</table>
text-end aligns the header and amount at the inline end of the cell. In a standard English page, that is the right side.
Bootstrap 3 or Bootstrap 4
<table class="table">
<tr>
<th>Product</th>
<th class="text-right">Total</th>
</tr>
<tr>
<td>Annual subscription</td>
<td class="text-right">$1,000,000.00</td>
</tr>
</table>
In Bootstrap 3 and 4, .text-right applies text-align: right.
Plain CSS alternative
If Bootstrap is not available, create your own reusable class:
.align-right {
text-align: right;
}
<td class="align-right">$1,000,000.00</td>
Step by Step Execution
Consider this Bootstrap 5 table row:
<tr>
<td>Cloud storage</td>
<td class="text-end">$250.00</td>
</tr>
- The browser creates a table row with two cells.
- The first
<td>has no alignment utility, so it uses the table or browser’s normal text alignment, usually left in an English document. - The second
<td>has thetext-endclass. - Bootstrap’s stylesheet contains a rule that sets the cell’s text alignment to the inline end.
- In a left-to-right layout,
$250.00is displayed against the right edge of that cell.
The value itself is unchanged. The class affects presentation only, not the number, currency, or table data.
Real World Use Cases
Text-alignment utilities are frequently used in data-heavy interfaces:
- Invoices: right-align line-item prices, tax, and invoice totals.
- Financial dashboards: align revenue, expenses, balances, and percentage changes.
- Shopping carts: align unit prices and order totals.
- Admin tables: place IDs, dates, quantities, and numeric metrics in consistently aligned columns.
- API monitoring pages: align response times, status counts, and request totals.
- Reports and exports: improve readability before users print or save a report as a PDF.
A common convention is to left-align descriptive text, such as product names, and right-align numerical values.
Real Codebase Usage
In real projects, developers usually apply alignment at the column level by adding the utility class to every matching <th> and <td>.
<th scope="col" class="text-end">Amount</th>
<td class="text-end">$49.99</td>
<td class="text-end">$125.00</td>
For responsive layouts in Bootstrap 5, use breakpoint variants when an alignment should change by screen width:
<td class="text-start text-md-end">$49.99</td>
This is left-aligned on small screens and end-aligned from the md breakpoint upward.
In template-driven applications, keep the value as data and use the class as display styling:
<td class="text-end">{{ formatCurrency(order.total) }}</td>
This separation matters: formatting code decides how a value is displayed, while the Bootstrap utility decides where it is positioned.
For repeated table designs, teams may also create a shared table component so all currency columns use the same formatting, spacing, and alignment rules.
Common Mistakes
Using a class that Bootstrap does not provide
This class does nothing unless you define it yourself:
<td class="align-right">$1,000.00</td>
Use Bootstrap’s version-appropriate utility instead:
<!-- Bootstrap 5 -->
<td class="text-end">$1,000.00</td>
<!-- Bootstrap 3 or 4 -->
<td class="text-right">$1,000.00</td>
Mixing Bootstrap versions
text-right is not the standard Bootstrap 5 utility, and text-end is not available in older Bootstrap releases. Check the version loaded by the project before selecting a class.
Applying the class to the wrong element
Applying alignment to a surrounding element may not affect a cell if a more specific table rule overrides it. Put the utility directly on the relevant <th> or <td>.
<td class="text-end">$99.00</td>
Expecting text alignment to size a column
text-end changes text position, not column width. Use table layout, width utilities, CSS sizing, or column definitions when you need to control widths.
Treating money as an unformatted raw number
Alignment cannot make 1000000 easy to read. Format currency separately, then align it:
<td class="text-end">$1,000,000.00</td>
Forgetting header alignment
If data is right-aligned but its heading remains left-aligned, the column can look inconsistent. Align the matching <th> too when that improves readability.
Comparisons
| Need | Bootstrap 3 / 4 | Bootstrap 5 | Notes |
|---|---|---|---|
| Align text left | .text-left | .text-start | start follows writing direction. |
| Center text | .text-center | .text-center | The class name is unchanged. |
| Align text right | .text-right | .text-end | Use end in Bootstrap 5. |
| Custom right alignment | Custom CSS | Custom CSS | Useful without Bootstrap or for project-specific rules. |
text-align aligns inline content inside an element. It is different from these layout tools:
| Tool | What it controls |
|---|---|
text-end | Position of text and inline content inside a cell |
text-center | Centers text and inline content inside a cell |
float-end | Floats an entire element toward one side |
Flexbox justify-content-end | Positions flex items within a flex container |
margin-start: auto | Pushes a block or flex item when the layout allows it |
Cheat Sheet
<!-- Bootstrap 5 -->
<td class="text-start">Description</td>
<td class="text-center">Status</td>
<td class="text-end">$49.99</td>
<!-- Bootstrap 3 and 4 -->
<td class="text-left">Description</td>
<td class="text-center">Status</td>
<td class="text-right">$49.99</td>
- Apply alignment utilities directly to
<th>and<td>elements. - Use
.text-endfor right alignment in Bootstrap 5. - Use
.text-rightfor right alignment in Bootstrap 3 and 4. - Use
.text-centerto center text in all of these versions. - In Bootstrap 5,
startandendadapt to text direction. - Alignment changes appearance only; it does not format a number or change column width.
- For a responsive Bootstrap 5 rule, use classes such as
.text-start.text-md-end.
FAQ
What Bootstrap class right-aligns text in a table cell?
Use .text-end in Bootstrap 5. Use .text-right in Bootstrap 3 or Bootstrap 4.
Can I use text-end on a <th> element?
Yes. Bootstrap text utility classes work on table headers and table data cells.
Why does align-right not work in Bootstrap?
align-right is not a standard Bootstrap text utility. It only works if your own stylesheet defines it.
Should currency be aligned to the right in a table?
Usually, yes. Right alignment makes amounts easier to compare vertically, especially when values have different numbers of digits.
Does text-end always mean right-aligned?
In a normal left-to-right document, yes. In a right-to-left document, end can be the left side. This behavior is intentional and supports internationalized layouts.
How do I align a value right only on larger screens in Bootstrap 5?
Use a responsive utility such as class="text-start text-md-end". It starts left-aligned and becomes end-aligned at the md breakpoint.
Does text alignment affect sorting or numeric calculations?
No. It only affects visual presentation. Sorting and calculations depend on the underlying data and application code.
Mini Project
Description
Build a compact invoice summary table. It demonstrates the common reporting convention of keeping descriptions easy to read on the left while placing quantities and currency totals in consistently aligned numeric columns.
Goal
Create a Bootstrap 5 invoice table with right-aligned quantity, price, and total columns.
Requirements
Use a Bootstrap-styled table with a header row and at least three product rows. Right-align the Quantity, Unit Price, and Total headers and values. Keep product descriptions left-aligned. Add a final Total row that clearly displays the order total.
Keep learning
Related questions
Add a Favicon to a Static HTML Page
Learn how to add a favicon to static HTML pages, use correct paths and icon formats, and troubleshoot browser caching and local-file issues.
Allow Only Numeric Input (0-9) in HTML Input Using jQuery
Learn how to allow only digits 0-9 in an HTML input using jQuery, with examples, validation tips, common mistakes, and best practices.
Apply CSS !important with jQuery .css()
Learn why jQuery .css() cannot set !important and how to use CSSStyleDeclaration.setProperty() to apply inline important styles safely.