Skip to content
Fix Code Error

How to align center the text in html table row?

March 13, 2021 by Code Error
Posted By: Anonymous

I am using an HTML <table> and I want to align the text of <td> to the center in each cell.

How do I center align the text horizontally and vertically?

Solution

Here is an example with CSS and inline style attributes:

td 
{
    height: 50px; 
    width: 50px;
}

#cssTable td 
{
    text-align: center; 
    vertical-align: middle;
}
<table border="1">
    <tr>
        <td style="text-align: center; vertical-align: middle;">Text</td>
        <td style="text-align: center; vertical-align: middle;">Text</td>
    </tr>
</table>

<table border="1" id="cssTable">
    <tr>
        <td>Text</td>
        <td>Text</td>
    </tr>
</table>

http://jsfiddle.net/j2h3xo9k/

EDIT: The valign attribute is deprecated in HTML5 and should not be used.

Answered By: Anonymous

Related Articles

  • Using Auto Layout in UITableView for dynamic cell layouts &…
  • assign flexbox cells the same width
  • Azure Sql : Unable to Replace HTML String
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't encode…
  • How to vertically align an image inside a div
  • Active tab issue on page load HTML
  • Centering in CSS Grid
  • How to vertically center a container in Bootstrap?
  • Navbar not filling width of page when reduced to mobile view
  • Fix top buttons on scroll of list below

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How can I open a cmd window in a specific location?

Next Post:

How do function pointers in C work?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error