# Character Position Absolute (HPA)

> Move the cursor to column n of the line it is on.

- **Sequence:** `CSI Pn ``
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.57 HPA – Character Position Absolute, p. 45](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n58/mode/1up)
- **VT510:** [HPA—Horizontal Position Absolute](https://vt100.net/docs/vt510-rm/HPA.html)

Move the cursor to column `Pn` of the line it is on, counting from 1. The
line does not change. A `0` is taken as `1`. The VT510 manual says that an
attempt to move past the last position on the line stops at the last
position.

This is [CHA](https://control-codes.page/csi/cha/index.html.md) under another final byte. ECMA-48 defines HPA in
terms of the *data* component and CHA in terms of the *presentation*
component, but a terminal has no separate data component, and for such a
device ECMA-48 reads the one as the other (§6, p. 14). libghostty-vt handles
the two with the same code.

The VT510 manual's one-line summary of HPA, at the top of its page, is a
copying error: it describes asking about free memory for programmable keys.
The description beneath it is the right one.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | No | not in the manual |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | Yes | [HPA](https://vt100.net/docs/vt510-rm/HPA.html) |
| xterm | patch 412, [xterm-411a](https://github.com/ThomasDickey/xterm-snapshots/tree/xterm-411a) | Yes |  |
| libghostty-vt | [0f171f6](https://github.com/ghostty-org/ghostty/tree/0f171f650a1cbbd6df4a2573b6b0c7de57cc6d90) | Yes | handled by the same code as CHA |
| kitty | 0.49.1, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/kitty.json) | Yes | passes the 3 cases that show it working |
| foot | 1.28.0, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/foot.json) | Yes | passes the 3 cases that show it working |
| pyte | 0.8.2, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/pyte.json) | No | fails the 3 cases that show it working |
| xterm.js headless | 6.0.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/xtermjs.json) | Yes | passes the 3 cases that show it working |
| alacritty_terminal | 0.26.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/alacritty.json) | Yes | passes the 3 cases that show it working |
| ConEmu | build 230724, its [documentation](https://conemu.github.io/en/AnsiEscapeCodes.html) | No | not in [ANSI escape codes](https://conemu.github.io/en/AnsiEscapeCodes.html) |
| rxvt-unicode | 9.31, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/urxvt.json) | Yes | passes the 3 cases that show it working |
| VTE | 0.84.1, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/vte.json) | Yes | passes the 3 cases that show it working |

## Validation

### HPA-1: To a column

Input, one step per line:

```text
\e[2;5H
\e[2`
X
```

Expected screen:

```text
|_____|
|_X___|
```

### HPA-2: To the first column by default

Input, one step per line:

```text
\e[1;4H
\e[`
X
```

Expected screen:

```text
|X____|
```

### HPA-3: Stops at the last column

Input, one step per line:

```text
\e[2;1H
\e[99`
X
```

Expected screen:

```text
|_____|
|____X|
```

---

This is the Markdown version of <https://control-codes.page/csi/hpa/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
