11 Vote

HTML: Align Text in Table at the Top

Question by Guest | Last update on 2023-11-02 | Created on 2016-07-23

I have some tables on my website, in which cells there are texts of different lengths. Sometimes only a word, sometimes several sentences.

Unfortunately, the text in the cell is centered vertically. However, I want the text to start always at the top left corner above and not somewhere in the middle.

Is this somehow possible using HTML formatting?

22 Votes

Just set the property vertical align (valign) of the corresponding cell to "top".

For example, this will align the first column to the top:

    <td valign="top">Content is aligned above</td>
    <td>Content is default aligned</td>
    <td valign="top">Content is aligned above</td>
    <td>Content is default aligned</td>

So, just insert valign="top" for the td's of choice - and the text should stick at the top.
Last update on 2023-11-02 | Created on 2016-07-23

ReplyPositive Negative
3Best Answer3 Votes

Alternatively, you can also work with CSS. The corresponding CSS property is called "vertical-align" and can take the values "top", "bottom" or "middle".

To align the text in table cells at the top, you can write the following:

td {
  vertical-align: top;

The beauty of this solution, compared to the solution with valign="top", is that you can define the CSS rule once and centrally in a CSS stylesheet without having to edit each cell of your table(s) individually. This also helps you to separate your content from your style instructions.
2023-11-02 at 01:39

ReplyPositive Negative

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.