Align attribute is obsolete

Udemy - 30 Amazing Days of HTML and CSS Learning
30 Amazing Days of HTML and CSS Learning
Learn HTML & CSS and start creating your own websites within 30 days

With HTML 4, you can horizontally align an element in a cell in a table using the align parameter, e.g.: <td align="right"> to horizontally align text to the right side of a cell. However, with HTML5, use of the align parameter for horizontally aligning text within elements of a table has been deprecated. E.g., if you check your HTML code for adherence to the HTML 5 standard with the Nu Html Checker provided by the World Wide Web Consortium, you will see an error similar to the following one displayed if you are using align in the HTML code for a table.

The align attribute on the td element is obsolete. Use CSS instead.
From line 118, column 5; to line 118, column 22
</tr>↩<tr><td align="right">;<b>Vir

So how can you achieve the same effect, but make your HTML code HTML 5 compliant using Cascading Style Sheets, instead? If you wanted to specify horizontal alignment of text in just one cell, you could use the following CSS code for that cell:

<td style="text-align: right;">

Or you could use text-align: left; or text-align: center;, if you wished to have the text left-aligned or centered, instead.

Or I could include the following style section in the HEAD section of the HTML code for the webpage, if I wanted all cells in any table on the page to have text within the cell aligned to the right side of the cell:

<style type="text/css">
   th, td { text-align: right; }

If you didn't want to use that alignment for every td or th in every table in a page, you could create a CSS class name, e.g., rightAligned, as shown below:

<style type="text/css">
   .rightAligned { text-align: top; }

You could then apply that class to any td in a table where you wanted elements within the cell to be aligned to the top of the cell. I.e.:

<td class="rightAligned">Some text</td>

Related articles:

  1. Valign attribute is obsolete
  2. Equivalent for cellpadding in CSS
  3. The width attribute on the table element is obsolete



Justdeals Daily Electronics Deals1x1 px