Text-align class for inside a table
To manage text alignment in a Bootstrap table, apply the text-left
, text-center
, or text-right
classes directly in your <td>
or <th>
elements.
Here's your quick fix:
In this, text aligns to the left, center, or right within the corresponding table cells.
How to go with the Bootstrap 5 flow
In Bootstrap 5, the text-start
and text-end
classes replace text-left
and text-right
. This change better supports right-to-left languages. Use them like so:
Responsive design with Bootstrap
Responsive design is vital for a top-notch user experience. Bootstrap 4 introduced text-sm-right
type of classes for easy responsive text alignment. Here’s an example:
This code aligns text to the right on bigger screens, but jumps to the left on small devices.
Roll your own alignment in tables
If you're pulling your hair out because Bootstrap doesn't quite give you what you need, you can use custom CSS classes for additional control and legibility. Now, you can define semantic classes like .price-label
or .price-value
with text-align: right
:
Overwrite those Bootstrap styles
When Utility Classes just don't cut it, override Bootstrap’s default styles. Make sure to load your styles after the bootstrap.css
file. Sometimes, you may need to use the !important
rule to stamp your authority:
Slap these styles directly on your table cell elements to see immediate results:
Text alignment use cases
For print-ready tables
In print-oriented tables, right-alignment keeps numbers neatly lined up:
Dashboard Interfaces
In dashboard interfaces, left or justified alignment makes data more digestible:
Web Accessibility
Right alignment is crucial for languages read from right to left. Bootstrap 5 shines here:
References
Was this article helpful?