# Backspace (BS)

> Move the cursor one column to the left.

- **Sequence:** `BS`
- **ECMA-48:** [§8.3.5 BS – Backspace, p. 34](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n47/mode/1up)
- **DEC STD 070:** [§5.4.4 Back Space, p. 5-63](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n317/mode/1up)
- **VT220:** [§4.2 Control Characters](https://vt100.net/docs/vt220-rm/chapter4.html#S4.2)
- **VT510:** [4.2 Control Characters](https://vt100.net/docs/vt510-rm/chapter4.html#S4.2)

Move the cursor one column to the left. Nothing is erased: the character
under the cursor stays where it is until something is written over it, which
is how a shell's line editor rubs out a character, with `BS`, a space and
another `BS`.

At the left margin, or the first column when there are no margins, the cursor
does not move. xterm's *reverse wraparound* mode (`CSI ? 45 h`) makes it
move to the end of the previous line instead; that mode is off by default and
not covered here.

If a wrap is pending, because the last thing written filled the last column,
the wrap is cancelled and the cursor moves left from the last column. xterm
handles BS as a one-column [`CursorBack`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/cursor.c#L121-L204), which clears
it.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | Yes | [§4.2 Control Characters](https://vt100.net/docs/vt220-rm/chapter4.html#S4.2) |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | Yes | [Table 4–1](https://vt100.net/docs/vt510-rm/chapter4.html#T4-1) |
| xterm | patch 412, [xterm-411a](https://github.com/ThomasDickey/xterm-snapshots/tree/xterm-411a) | Yes | stops at the left margin; reverse wraparound (`CSI ? 45 h`) is off by default |
| libghostty-vt | [0f171f6](https://github.com/ghostty-org/ghostty/tree/0f171f650a1cbbd6df4a2573b6b0c7de57cc6d90) | Yes | BS-5: moves past the left margin |
| kitty | 0.49.1, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/kitty.json) | Partly | fails BS-4 of 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) | Partly | fails BS-4 of 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) | Yes | passes 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 |
| rxvt-unicode | 9.31, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/urxvt.json) | Partly | fails BS-4 of 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

### BS-1: Overwrite the previous character

Input, one step per line:

```text
ABC
\b
X
```

Expected screen:

```text
|ABX__|
cursor 1,4
```

### BS-2: Nothing happens in the first column

Input, one step per line:

```text
\b\b
X
```

Expected screen:

```text
|X____|
cursor 1,2
```

### BS-3: Rubbing out a character

Input, one step per line:

```text
ABC
\b\s\b    # the line editor's erase
```

Expected screen:

```text
|AB___|
cursor 1,3
```

### BS-4: From a pending wrap

Input, one step per line:

```text
ABCDE     # fills the line; a wrap is pending
\b
X
```

Expected screen:

```text
|ABCXE|
cursor 1,5
```

### BS-5: Stops at the left margin

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
\e[?69h   # allow left and right margins
\e[3;5s   # margins at columns 3 and 5
\e[1;3H   # on the left margin
\b
X
```

Expected screen:

```text
|__X__|
```

libghostty-vt implements BS as a one-column [CUB](https://control-codes.page/csi/cub/index.html.md), and has the
same difference: the cursor moves past the left margin into column 2.
The VT510 manual says that at the left margin "no action occurs", and
esctest2's `test_BS_StopsAtLeftMargin` expects the cursor to stay put, as
xterm does.

---

This is the Markdown version of <https://control-codes.page/c0/bs/>. 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>.
