HTML char Attribute

The obsolete HTML char attribute was intended to specify a character used to align content within table columns and cells, such as aligning numeric values around a decimal point.

Historical Syntax

The char attribute specified the character around which table cell content was intended to be aligned. A decimal point was a common example:

<tbody char=".">
  <tr>
    <td>12.50</td>
  </tr>
  <tr>
    <td>125.75</td>
  </tr>
</tbody>

The attribute was associated with character-based alignment and was typically used with the historical align="char" value. The related charoff attribute could specify an offset for the alignment character.

Historical Elements

The char attribute was historically associated with several table-related elements.

Element Historical Purpose
<col> Specified an alignment character for cells associated with a table column.
<colgroup> Specified an alignment character for cells associated with a group of table columns.
<thead>, <tbody>, <tfoot> Specified an alignment character for cells within a table row group.
<tr> Specified an alignment character for cells within a table row.
<td>, <th> Specified an alignment character for an individual table cell.

Historical Use

The char attribute was designed for tables containing values that were easier to compare when aligned around a particular character. Numeric values containing decimal points are a common example.

For example, values such as 9.50, 125.75, and 1000.00 could theoretically be aligned so that their decimal points appeared in the same vertical position. The char attribute identified the decimal point as the alignment character.

In practice, character-based table alignment was not implemented consistently enough across browsers to become a dependable method of laying out table data.

Why It Became Obsolete

The char attribute was part of an older system of table presentation attributes. Character-based alignment received limited and inconsistent browser support, making it unreliable for webpage layouts.

Modern HTML separates table structure from presentation. General text alignment can be controlled with CSS, while specialized alignment around a decimal point or another character may require a different markup or layout technique.

Modern Alternative

There is no direct CSS equivalent of the obsolete char attribute. For ordinary table alignment, use CSS properties such as text-align. Numeric table data is commonly right-aligned so values can be compared more easily.

Historical HTML

<table>
  <tbody align="char" char=".">
    <tr>
      <td>9.50</td>
    </tr>
    <tr>
      <td>125.75</td>
    </tr>
    <tr>
      <td>1000.00</td>
    </tr>
  </tbody>
</table>

Modern HTML and CSS

<table class="price-table">
  <tr>
    <th>Price</th>
  </tr>
  <tr>
    <td>9.50</td>
  </tr>
  <tr>
    <td>125.75</td>
  </tr>
  <tr>
    <td>1000.00</td>
  </tr>
</table>

<style>
.price-table th,
.price-table td {
  text-align: right;
}
</style>

This CSS example right-aligns the numeric values rather than attempting to reproduce character-based alignment. If exact alignment around a decimal point is required, additional markup or another layout technique may be necessary.

Play in Editor

Learn More About CSS Alignment

The CSS tutorials provide more information about aligning text and styling tables:

Legacy Browser Support

The char attribute was defined for character-based table alignment in earlier HTML specifications, but browser support for its intended behavior was limited and inconsistent.

Older source code may still contain the attribute, but it should not be relied on for alignment in modern browsers. Use CSS for ordinary text alignment and another layout technique when exact character-based alignment is required.

For additional information about historical browser compatibility, visit Can I Use? . Search for the HTML element or attribute you want to check. Search results can include related HTML features, element attributes, APIs, and other technologies, so select the result that most closely matches the legacy feature you are researching.

Other obsolete HTML attributes historically associated with table alignment include:

  • charoff - Historically used to specify an offset for the alignment character.
  • align - Historically used to control horizontal alignment, including character-based table alignment.
  • valign - Historically used to control vertical alignment.

Specifications

The char attribute is obsolete in modern HTML and should not be used for table alignment. See the WHATWG HTML Living Standard for information about obsolete and non-conforming features.