HTML charoff Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 2 Examples
Tables & Layout

Introduction

The charoff attribute is used in HTML to specify the offset of the alignment character in a table cell. It works together with align="char" and the char attribute to fine-tune where content aligns relative to a chosen character—such as shifting decimal-aligned numbers a few pixels from the decimal point.

What You’ll Learn

01

Offset

Pixels or %.

02

With char

Partner attr.

03

align char

Required pair.

04

Table cells

td, th.

05

charOff

DOM property.

06

Deprecated

Use CSS.

Purpose of charoff Attribute

The primary purpose of the charoff attribute is to adjust the horizontal position of text aligned on a character within a table cell. After you choose an alignment character with char, charoff moves the alignment point by a specified number of pixels or a percentage of the cell width. This helps fine-tune the visual presentation of tabular data in legacy HTML documents.

💡
Requires align="char" and char

charoff only has meaning when used with align="char" and a char value. It does not replace left, center, or right alignment on its own.

📝 Syntax

Add charoff alongside align="char" and char on a table cell:

charoff.html
<td align="char" char="." charoff="10">12.5</td>

Syntax Rules

  • Use with align="char" and char on the same element.
  • Value is a length in pixels (e.g. 10) or a percentage (e.g. 5%).
  • Positive values offset from the left side of the cell toward the alignment character.
  • Applies to table elements: td, th, col, and related sections.
  • For modern layouts, use CSS padding or text-align instead.

💎 Values

The charoff attribute accepts numerical values to determine the offset from the alignment character. The most common value types include:

  • Pixels — A plain number such as 10 means 10 pixels of offset.
  • Percentage — A value like 5% offsets by a percentage of the cell’s width.
charoff-values.html
<td align="char" char="." charoff="10">12.50</td>
<td align="char" char=":" charoff="5%">9:30</td>

<!-- CSS alternative -->
<style>
  .numeric { text-align: right; padding-right: 10px; }
</style>

⚡ Quick Reference

AttributePurposeCSS Alternative
charoff="10"10px offset from char pointpadding-left: 10px;
charoff="5%"5% of cell width offsetpadding-left: 5%;
align="char"Enables char alignmentRequired with char and charoff
charAlignment characterN/A (CSS has no direct equivalent)
Elementstd, th, col, etc.Style cells or columns
HTML5 statusDeprecatedUse CSS for new code

Applicable Elements

ElementSupported?Notes
<td>, <th>Yes (legacy)Most common: offset numeric or time columns
<col>, <colgroup>Yes (legacy)Apply offset to entire columns
<tr>, <tbody>, <thead>, <tfoot>Yes (legacy)May inherit to descendant cells
<table>No (directly)Set on cells or column groups
<div>NoTable-only legacy attribute

Examples Gallery

Implementation example with charoff offset and dynamic JavaScript charOff.

👀 Live Preview

Table row showing char alignment with a 10-pixel charoff offset (visual effect may vary in modern browsers):

12.50Center-alignedRight-aligned

Modern browsers may not visibly apply charoff. Use CSS padding or text-align for reliable layout.

Implementation Example

Let’s look at a simple example of how to use the charoff attribute in an HTML table:

index.html
<table border="1">
  <tr>
    <td align="char" char="." charoff="10">12.50</td>
    <td align="center">Center-aligned</td>
    <td align="right">Right-aligned</td>
  </tr>
</table>
Try It Yourself

How It Works

In this example, the first <td> uses align="char", char=".", and charoff="10". The browser aligns content on the decimal point and then applies a horizontal offset of 10 pixels from that alignment position.

Dynamic Values with JavaScript

You can also dynamically set the charoff attribute using JavaScript. This can be useful when you want to adjust the alignment offset based on user interactions or other dynamic factors:

index.html
<td id="dynamicCell" align="char" char=":">Value: 100:200</td>

<script>
  // Dynamically set charoff for a table cell
  document.getElementById("dynamicCell").charOff = "5%";
</script>
Try It Yourself

How It Works

In this script, the charOff property of the cell with id dynamicCell is set to 5%, shifting the alignment offset by five percent of the cell width. Note the capital O in the DOM property name charOff.

♿ Accessibility

  • Offset is visual only — Screen readers announce cell text, not charoff positioning.
  • Use clear headers — Pair aligned columns with <th scope="col"> labels.
  • Do not rely on charoff — Since support is deprecated, use CSS for layouts users depend on.
  • Keep content readable — Large offsets can push text awkwardly on narrow screens.
  • Test with real data — Verify numeric columns remain scannable without charoff rendering.

🧠 How charoff Works

1

Author sets char trio

Add align="char", char, and charoff on a table cell.

Markup
2

Browser finds char point

The layout engine locates the alignment character in the cell content.

Parsing
3

Offset is applied

charoff shifts the alignment position by pixels or a percentage.

Layout
=

Fine-tuned column alignment

In modern projects, CSS padding and text-align replace charoff.

Browser Support

The charoff attribute is deprecated in HTML5. Most modern browsers no longer apply visible character offsets, even though legacy markup may still parse.

⚠️ HTML4 legacy · Deprecated

Limited modern rendering

Use CSS padding and text-align for reliable table cell positioning.

Legacy Limited support
Google Chrome Attribute parsed
Deprecated
Mozilla Firefox Attribute parsed
Deprecated
Apple Safari Attribute parsed
Deprecated
Microsoft Edge Attribute parsed
Deprecated
charoff attribute Deprecated

Bottom line: Learn charoff for legacy HTML tables, but use CSS padding and alignment for new numeric columns.

💡 Best Practices

✅ Do

  • Always pair charoff with align="char" and char
  • Use CSS padding for offset control in new tables
  • Experiment with small pixel values when reading legacy markup
  • Document deprecated attributes in maintained codebases
  • Test tables across browsers when charoff is required

❌ Don’t

  • Use charoff alone without align="char" and char
  • Expect visible offset in all modern browsers
  • Confuse charoff with the unrelated charset attribute
  • Use charoff for general left/center/right alignment
  • Rely on charoff for responsive financial dashboards
  • Use the charoff attribute sparingly and only when necessary to adjust alignment of text within table cells.
  • Experiment with different charoff values to achieve the desired visual presentation of tabular data in legacy documents.
  • Test your tables across different browsers to ensure consistent alignment behavior.

Conclusion

The charoff attribute provides a means to adjust the horizontal offset of character-aligned text within HTML table cells. Used with align="char" and char, it offered fine-grained control over numeric and delimited column formatting in legacy HTML.

For modern development, CSS padding, text-align, and font-variant-numeric deliver reliable results. Learn charoff to understand older markup, then prefer CSS in new projects.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about charoff

Bookmark these before working with legacy HTML tables.

5
Core concepts
📝 02

With char

Partner attr.

Syntax
03

align char

Required.

Pair
⚙️ 04

charOff

DOM property.

JS
⚠️ 05

Deprecated

Use CSS.

Modern

❓ Frequently Asked Questions

It sets the horizontal offset from the alignment character when align="char" and char are used.
No. charoff only works meaningfully with align="char" and a char value on the same element.
A pixel length (e.g. 10) or a percentage (e.g. 5%) offset from the char alignment point.
It is deprecated. Modern browsers may not render the offset visibly. Use CSS instead.
Assign element.charOff = "5%" or use setAttribute("charoff", "10"). Note the capital O in charOff.
td.numeric { text-align: right; padding-left: 10px; font-variant-numeric: tabular-nums; }

Fine-tune character alignment in tables

Practice the legacy charoff attribute with pixel and percentage offsets, and compare it with modern CSS padding.

Try table example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful