# Line Feed (LF)

> Move the cursor down one line, scrolling at the bottom margin.

- **Sequence:** `LF`
- **ECMA-48:** [§8.3.74 LF – Line Feed, p. 49](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n62/mode/1up)
- **DEC STD 070:** [§5.4.4 Line Feed, p. 5-59](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n313/mode/1up)
- **VT510:** [4.2 Control Characters](https://vt100.net/docs/vt510-rm/chapter4.html#S4.2)

Move the cursor down one line, keeping its column. If the cursor is on the
bottom margin (the last line, unless a scrolling region has been set with
DECSTBM), the lines of the scrolling region move up by one instead: the
top line leaves the region, and a blank line appears at the bottom. Lines
outside the region do not move.

A line feed does **not** return the cursor to the left margin. When a program
prints `\n`, it is the terminal *driver*, not the terminal, that turns it into
`\r\n`. Line feed/new line mode (`CSI 20 h`, LNM) makes the terminal do it
instead, and is off by default.

[Vertical tab](https://control-codes.page/c0/vt/index.html.md) (VT, `0B`) and [form feed](https://control-codes.page/c0/ff/index.html.md) (FF, `0C`) do the same thing as a
line feed.

## Validation

### LF-1: Down, not back

Input, one step per line:

```text
AB
\n
C
```

Expected screen:

```text
|AB___|
|__C__|
|_____|
cursor 2,4
```

### LF-2: Scrolls at the bottom

Input, one step per line:

```text
A\r\nB\r\nC
\n
D
```

Expected screen:

```text
|B____|
|C____|
|_D___|
```

### LF-3: Scrolls only the scrolling region

Input, one step per line:

```text
1\r\n2\r\n3\r\n4
\e[2;3r   # region is lines 2 and 3; homes the cursor
\e[3;1H
\n
X
```

Expected screen:

```text
|1____|
|3____|
|X____|
|4____|
```

### LF-4: With line feed/new line mode

Input, one step per line:

```text
\e[20h    # LNM
AB
\n
C
\e[20l
```

Expected screen:

```text
|AB___|
|C____|
cursor 2,2
```

---

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