HTML charoff Attribute
The obsolete HTML charoff attribute was intended to specify the offset of table cell content from an alignment character identified by the char attribute.
charoff attribute is obsolete and should not be used in modern HTML. There is no direct CSS property that reproduces its intended character-offset behavior.
Historical Syntax
The charoff attribute was used with the char attribute and character-based alignment. For example, a decimal point could be selected as the alignment character and charoff could specify its offset:
<tbody align="char" char="." charoff="50%">
<tr>
<td>9.50</td>
</tr>
<tr>
<td>125.75</td>
</tr>
</tbody>
The attribute did not perform the character alignment by itself. It was intended to adjust the position of content that was already using character-based alignment.
Historical Elements
The charoff attribute was historically associated with several table-related elements.
| Element | Historical Purpose |
|---|---|
<col> |
Specified the offset of the alignment character for cells associated with a table column. |
<colgroup> |
Specified the offset of the alignment character for cells associated with a group of table columns. |
<thead>, <tbody>, <tfoot> |
Specified the alignment character offset for cells within a table row group. |
<tr> |
Specified the alignment character offset for cells within a table row. |
<td>, <th> |
Specified the alignment character offset for an individual table cell. |
Historical Use
The charoff attribute was designed to work with char and character-based table alignment. The char attribute identified a character, such as a decimal point, while charoff was intended to control the position of that alignment character within the available cell space.
This could theoretically provide more precise control over columns containing numbers or other values that needed to line up around a particular character.
In practice, browser support for character-based alignment and charoff was limited and inconsistent, so authors could not depend on the intended behavior across browsers.
Why It Became Obsolete
The charoff attribute was part of an older system of HTML table presentation. Its usefulness depended on character-based alignment, which itself was not reliably implemented by browsers.
Modern HTML keeps table structure separate from presentation. CSS provides dependable tools for general alignment and spacing, although it does not provide a direct equivalent of the historical charoff behavior.
Modern Alternative
There is no direct CSS equivalent of the obsolete charoff attribute. For ordinary table data, CSS properties such as text-align and padding can be used to control the general position and spacing of cell content.
Historical HTML
<table>
<tbody align="char" char="." charoff="50%">
<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;
padding: 8px 16px;
}
</style>
This modern example does not reproduce the historical character offset. Instead, it uses right alignment and padding to create a consistent presentation for numeric table data. If exact alignment around a decimal point or another character is required, additional markup or another layout technique may be necessary.
Play in EditorLearn More About CSS Alignment and Spacing
The CSS tutorials provide more information about aligning and spacing table content:
- CSS Text Alignment - Learn how to control the horizontal alignment of text with CSS.
- CSS Padding - Learn how to control the space between content and the edges of an element.
- CSS Styling Tables - Learn how to control the presentation and alignment of table content.
Legacy Browser Support
The charoff attribute was defined for use with character-based table alignment in earlier HTML specifications, but support for its intended behavior was limited and inconsistent across browsers.
Older source code may still contain the attribute, but it should not be relied on in modern webpages. Use CSS for general alignment and spacing, and use another layout technique when exact character-based positioning 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.
Related Attributes
Other obsolete HTML attributes historically associated with table alignment include:
Specifications
The charoff 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.
