# Scroll Down (SD)

> Move the contents of the scrolling region down n lines.

- **Sequence:** `CSI Pn T`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.113 SD – Scroll Down, p. 59](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n72/mode/1up)
- **DEC STD 070:** [§5.5 Pan Up (Scroll Down), p. 5-92](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n346/mode/1up)
- **VT510:** [SD—Pan Up](https://vt100.net/docs/vt510-rm/SD.html)

Move the lines of the scrolling region down `Pn` lines. The bottom `Pn` lines
of the region are lost, and `Pn` blank lines appear at the top margin. A `0`
is taken as `1`. The cursor does not move.

Like [SU](https://control-codes.page/csi/su/index.html.md), and unlike [IL](https://control-codes.page/csi/il/index.html.md), SD scrolls the whole
scrolling region wherever the cursor is, and with left and right margins set
moves only the part of each line between them.

DEC STD 070 and the VT510 manual call it *Pan Up*: in DEC's windowing
extension it moves the window up a page of display memory taller than the
screen, bringing a new line into view at the top, rather than moving any
data. The SU page explains the difference. xterm, like libghostty-vt, moves
the lines, and documents `CSI Ps T` as "Scroll down Ps lines".

xterm also scrolls down for `CSI Ps ^`, which ECMA-48 assigns to
[SIMD](https://control-codes.page/csi/simd/index.html.md); that page explains why.

With five parameters, `CSI Ps ; Ps ; Ps ; Ps ; Ps T` is a different sequence
in xterm, XTHIMOUSE, which starts highlight mouse tracking.

## Validation

### SD-1: Scroll one line

Input, one step per line:

```text
1\r\n2\r\n3\r\n4
\e[2;3H
\e[T
```

Expected screen:

```text
|_____|
|1____|
|2____|
|3____|
cursor 2,3
```

### SD-2: Scroll two lines

Input, one step per line:

```text
1\r\n2\r\n3\r\n4
\e[2T
```

Expected screen:

```text
|_____|
|_____|
|1____|
|2____|
```

### SD-3: The scrolling region, with the cursor outside it

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, above it
\e[T
```

Expected screen:

```text
|1____|
|_____|
|2____|
|4____|
cursor 1,1
```

### SD-4: Inside left and right margins

Input, one step per line:

```text
abcde\r\nfghij\r\nklmno\r\npqrst\r\nuvwxy
\e[?69h   # allow left and right margins
\e[2;4s   # margins at columns 2 and 4
\e[2;3H
\e[2T
```

Expected screen:

```text
|a___e|
|f___j|
|kbcdo|
|pghit|
|ulmny|
```

---

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