# Terminal control sequences

> A reference for terminal control sequences, with every example run live in libghostty-vt.

A terminal takes one stream of bytes. Most of it is text to put on the
screen, and the rest are *control sequences*: instructions to move the
cursor, erase part of the screen, change colors, set the window title,
and much else. This site documents a handful of them.

Each page states what a sequence does and then gives **validation cases**: a
sequence of input and the screen it should leave behind. Those cases are not
pictures. When you open a page your browser loads
[libghostty-vt](https://github.com/ghostty-org/ghostty), the terminal emulation
core of Ghostty, compiled to WebAssembly, feeds every case into a real
terminal, and shows what came out next to what was expected. You can step
through a case one line of input at a time and watch the cursor move.

The tally in the last column is computed as this page loads, by running every
case on every page. The [notation](https://control-codes.page/notation/index.html.md) page explains how cases are
written.

## C0 control characters

- [BS: Backspace](https://control-codes.page/c0/bs/index.html.md): Move the cursor one column to the left.
- [BEL: Bell](https://control-codes.page/c0/bel/index.html.md): Ring the terminal's bell.
- [CAN: Cancel](https://control-codes.page/c0/can/index.html.md): Abandon the escape sequence, control sequence or control string in progress.
- [CR: Carriage Return](https://control-codes.page/c0/cr/index.html.md): Move the cursor to the left margin of the current line.
- [DC1: Device Control One](https://control-codes.page/c0/dc1/index.html.md): XON and XOFF: flow control for what the terminal sends, with no effect on the screen.
- [ENQ: Enquiry](https://control-codes.page/c0/enq/index.html.md): Ask the terminal to send its answerback message.
- [ESC: Escape](https://control-codes.page/c0/esc/index.html.md): Begin an escape sequence, abandoning any sequence already in progress.
- [FF: Form Feed](https://control-codes.page/c0/ff/index.html.md): Move the cursor down one line, exactly as a line feed does.
- [HT: Horizontal Tab](https://control-codes.page/c0/ht/index.html.md): Move the cursor right to the next tab stop.
- [LF: Line Feed](https://control-codes.page/c0/lf/index.html.md): Move the cursor down one line, scrolling at the bottom margin.
- [NUL: Null](https://control-codes.page/c0/nul/index.html.md): A byte that carries nothing and is ignored.
- [SO: Shift Out](https://control-codes.page/c0/so/index.html.md): Switch the characters printed to the G1 set, and back to G0.
- [SUB: Substitute](https://control-codes.page/c0/sub/index.html.md): Display an error character in place of something that could not be received, abandoning any sequence in progress.
- [VT: Vertical Tab](https://control-codes.page/c0/vt/index.html.md): Move the cursor down one line, exactly as a line feed does.

## Escape sequences

- [DECBI: Back Index](https://control-codes.page/esc/decbi/index.html.md): Move the cursor one column, scrolling the region sideways at the margin.
- [CSI: Control Sequence Introducer](https://control-codes.page/esc/csi/index.html.md): Begin a control sequence: parameters, intermediates and a final byte.
- [DCS: Device Control String](https://control-codes.page/esc/dcs/index.html.md): Open a control string carrying commands for the terminal itself.
- [DECDLD: Down Line Load](https://control-codes.page/esc/decdld/index.html.md): Load the glyphs of a soft character set, which can then be designated like any other.
- [HTS: Horizontal Tabulation Set](https://control-codes.page/esc/hts/index.html.md): Set a tab stop at the cursor's column.
- [DECKPAM: Keypad Application Mode](https://control-codes.page/esc/deckpam/index.html.md): Choose what the numeric keypad sends: its digits or application codes.
- [DECDWL: Double-Width Line](https://control-codes.page/esc/decdwl/index.html.md): Make the cursor's line double-width or double-height, or put it back to single-width.
- [LS2: Locking Shift Two](https://control-codes.page/esc/ls2/index.html.md): Switch the characters printed to the G2 or G3 set.
- [NEL: Next Line](https://control-codes.page/esc/nel/index.html.md): Move the cursor to the start of the next line, scrolling at the bottom margin.
- [XTGETXRES: Request Resource Values](https://control-codes.page/esc/xtgetxres/index.html.md): Ask xterm for the value of one of its X resources.
- [DECRQSS: Request Selection or Setting](https://control-codes.page/esc/decrqss/index.html.md): Ask for the current setting of a function, as the sequence that would set it.
- [XTGETTCAP: Request Termcap/Terminfo String](https://control-codes.page/esc/xtgettcap/index.html.md): Ask the terminal what a key sends, or for one of a few of its capabilities, by its terminfo or termcap name.
- [RIS: Reset to Initial State](https://control-codes.page/esc/ris/index.html.md): Reset the terminal to the state it has when switched on.
- [RI: Reverse Index](https://control-codes.page/esc/ri/index.html.md): Move the cursor up one line, scrolling down at the top margin.
- [DECSC: Save Cursor](https://control-codes.page/esc/decsc/index.html.md): Save the cursor and its attributes, and later put them back.
- [DECALN: Screen Alignment Test](https://control-codes.page/esc/decaln/index.html.md): Fill the screen with the letter E.
- [XTSETTCAP: Set Termcap Data](https://control-codes.page/esc/xtsettcap/index.html.md): Tell xterm which terminal description to take its function keys from.
- [SS2: Single Shift Two](https://control-codes.page/esc/ss2/index.html.md): Print the next character from the G2 or G3 set.
- [SPA: Start of Guarded Area](https://control-codes.page/esc/spa/index.html.md): Mark the characters written in between as protected from erasure.
- [SOS: Start of String](https://control-codes.page/esc/sos/index.html.md): Open a control string whose content the terminal itself does not act on.
- [ST: String Terminator](https://control-codes.page/esc/st/index.html.md): End a control string, such as an operating system command or a device control string.
- [DECUDK: User Defined Keys](https://control-codes.page/esc/decudk/index.html.md): Load the strings the function keys send, and optionally lock them against being loaded again.
- [DECAUPSS: Assign User-Preference Supplemental Set](https://control-codes.page/esc/decaupss/index.html.md): Choose which supplemental character set is the user's preferred one, or ask which it is.

## Control sequences

- [DECCARA: Change Attributes in Rectangular Area](https://control-codes.page/csi/deccara/index.html.md): Change or reverse the rendition of a rectangle of the screen without rewriting its characters.
- [HPA: Character Position Absolute](https://control-codes.page/csi/hpa/index.html.md): Move the cursor to column n of the line it is on.
- [HPB: Character Position Backward](https://control-codes.page/csi/hpb/index.html.md): Move the cursor left n columns.
- [HPR: Character Position Forward](https://control-codes.page/csi/hpr/index.html.md): Move the cursor right n columns.
- [DECCRA: Copy Rectangular Area](https://control-codes.page/csi/deccra/index.html.md): Copy a rectangle of the screen, characters and attributes, to another place.
- [CUB: Cursor Backward](https://control-codes.page/csi/cub/index.html.md): Move the cursor left n columns.
- [CBT: Cursor Backward Tabulation](https://control-codes.page/csi/cbt/index.html.md): Move the cursor back to the previous tab stop, n times.
- [CHA: Cursor Character Absolute](https://control-codes.page/csi/cha/index.html.md): Move the cursor to column n of the line it is on.
- [CUD: Cursor Down](https://control-codes.page/csi/cud/index.html.md): Move the cursor down n lines.
- [CUF: Cursor Forward](https://control-codes.page/csi/cuf/index.html.md): Move the cursor right n columns.
- [CHT: Cursor Horizontal Tabulation](https://control-codes.page/csi/cht/index.html.md): Move the cursor forward n tab stops.
- [CNL: Cursor Next Line](https://control-codes.page/csi/cnl/index.html.md): Move the cursor down n lines, to the start of the line.
- [CUP: Cursor Position](https://control-codes.page/csi/cup/index.html.md): Move the cursor to a given line and column.
- [CPL: Cursor Preceding Line](https://control-codes.page/csi/cpl/index.html.md): Move the cursor up n lines, to the start of the line.
- [CTC: Cursor Tabulation Control](https://control-codes.page/csi/ctc/index.html.md): Set or clear tab stops: at the cursor, or all of them.
- [CUU: Cursor Up](https://control-codes.page/csi/cuu/index.html.md): Move the cursor up n lines.
- [DECDSR: DEC Device Status Reports](https://control-codes.page/csi/decdsr/index.html.md): DEC's private status requests: the extended cursor position, the printer, the keyboard, macro space and the like.
- [DCH: Delete Character](https://control-codes.page/csi/dch/index.html.md): Delete n characters at the cursor, pulling the rest of the line left.
- [DL: Delete Line](https://control-codes.page/csi/dl/index.html.md): Delete n lines at the cursor, pulling the lines below it up.
- [DA: Device Attributes](https://control-codes.page/csi/da/index.html.md): Ask the terminal what kind of terminal it is.
- [DSR: Device Status Report](https://control-codes.page/csi/dsr/index.html.md): Ask the terminal for its status or for the cursor position, and get a report back.
- [ECH: Erase Character](https://control-codes.page/csi/ech/index.html.md): Blank n characters from the cursor rightwards, without moving anything.
- [ED: Erase in Display](https://control-codes.page/csi/ed/index.html.md): Erase part or all of the screen.
- [EL: Erase in Line](https://control-codes.page/csi/el/index.html.md): Erase part or all of the cursor's line.
- [DECERA: Erase Rectangular Area](https://control-codes.page/csi/decera/index.html.md): Erase every character in a rectangle of the screen.
- [DECFRA: Fill Rectangular Area](https://control-codes.page/csi/decfra/index.html.md): Fill a rectangle of the screen with one character, in the current rendition.
- [HVP: Horizontal and Vertical Position](https://control-codes.page/csi/hvp/index.html.md): Move the cursor to a given line and column, as CUP does.
- [DECIC: Insert Column](https://control-codes.page/csi/decic/index.html.md): Insert or delete whole columns at the cursor, shifting the rest of the scrolling region sideways.
- [ICH: Insert Character](https://control-codes.page/csi/ich/index.html.md): Insert n blank cells at the cursor, shifting the rest of the line right.
- [IL: Insert Line](https://control-codes.page/csi/il/index.html.md): Insert n blank lines at the cursor, pushing the lines below it down.
- [DECTST: Invoke Confidence Test](https://control-codes.page/csi/dectst/index.html.md): Run the terminal's own self-tests, after which nothing about its state can be relied on.
- [XTMODKEYS: Set Key Modifier Options](https://control-codes.page/csi/xtmodkeys/index.html.md): Choose how keys pressed with Shift, Control or Alt are sent, and ask what is chosen.
- [CSI = u: Kitty Keyboard Protocol](https://control-codes.page/csi/kitty-keyboard/index.html.md): Ask the terminal to report keys unambiguously, with every modifier and with releases, through a stack of flags.
- [VPA: Line Position Absolute](https://control-codes.page/csi/vpa/index.html.md): Move the cursor to line n, keeping its column.
- [VPB: Line Position Backward](https://control-codes.page/csi/vpb/index.html.md): Move the cursor up n lines, keeping its column.
- [VPR: Line Position Forward](https://control-codes.page/csi/vpr/index.html.md): Move the cursor down n lines, keeping its column.
- [DECELR: Enable Locator Reports](https://control-codes.page/csi/decelr/index.html.md): Report the position of a mouse or tablet, the locator, to the host.
- [MC: Media Copy](https://control-codes.page/csi/mc/index.html.md): Print the screen, or send what the host sends to a printer instead of the screen.
- [NP: Next Page](https://control-codes.page/csi/np/index.html.md): Move to another page of display memory, on terminals that have more than one.
- [REP: Repeat](https://control-codes.page/csi/rep/index.html.md): Print the character before it n more times.
- [XTVERSION: Report Version](https://control-codes.page/csi/xtversion/index.html.md): Ask the terminal for its name and version.
- [DECRQCRA: Request Checksum of Rectangular Area](https://control-codes.page/csi/decrqcra/index.html.md): Ask for a checksum of part of the screen, to check it has not changed.
- [DECRQM: Request Mode](https://control-codes.page/csi/decrqm/index.html.md): Ask the terminal whether a mode is set, and get a DECRPM report back.
- [DECRQPSR: Request Presentation State Report](https://control-codes.page/csi/decrqpsr/index.html.md): Ask for the cursor's state or the tab stops, as a report that can be sent back later to restore them.
- [SD: Scroll Down](https://control-codes.page/csi/sd/index.html.md): Move the contents of the scrolling region down n lines.
- [SL: Scroll Left](https://control-codes.page/csi/sl/index.html.md): Move the contents of the scrolling region left or right by n columns.
- [SU: Scroll Up](https://control-codes.page/csi/su/index.html.md): Move the contents of the scrolling region up n lines.
- [DECSR: Secure Reset](https://control-codes.page/csi/decsr/index.html.md): Reset the terminal to its power-up state, erase everything the host could have stored in it, and confirm that it was done.
- [DECSCL: Select Conformance Level](https://control-codes.page/csi/decscl/index.html.md): Make the terminal behave as an earlier level of DEC terminal, with a soft reset.
- [SGR: Select Graphic Rendition](https://control-codes.page/csi/sgr/index.html.md): Set the colors and attributes of the characters written after it.
- [SIMD: Select Implicit Movement Direction](https://control-codes.page/csi/simd/index.html.md): ECMA-48's choice of which way text runs, which xterm takes as Scroll Down.
- [DECSNLS: Select Number of Lines per Screen](https://control-codes.page/csi/decsnls/index.html.md): Choose how many lines the screen shows at once.
- [DECSCA: Select Character Protection Attribute](https://control-codes.page/csi/decsca/index.html.md): Protect characters from erasure, then erase everything else on the line or the screen.
- [DECSCPP: Set Columns Per Page](https://control-codes.page/csi/decscpp/index.html.md): Make the page 80 or 132 columns wide, without clearing it.
- [DECSCUSR: Set Cursor Style](https://control-codes.page/csi/decscusr/index.html.md): Choose the cursor's shape, and whether it blinks.
- [DECSLRM: Set Left and Right Margins](https://control-codes.page/csi/decslrm/index.html.md): Set the columns of the scrolling region, once left and right margins are enabled.
- [SM: Set Mode](https://control-codes.page/csi/sm/index.html.md): Turn terminal modes on and off.
- [DECSTBM: Set Top and Bottom Margins](https://control-codes.page/csi/decstbm/index.html.md): Set the lines of the scrolling region.
- [DECSTR: Soft Terminal Reset](https://control-codes.page/csi/decstr/index.html.md): Put the modes and settings a program may have changed back to their defaults, leaving the screen alone.
- [DECSASD: Select Active Status Display](https://control-codes.page/csi/decsasd/index.html.md): Show a status line below the screen, and send text to it instead of the screen.
- [TBC: Tabulation Clear](https://control-codes.page/csi/tbc/index.html.md): Clear the tab stop at the cursor, or every tab stop.
- [DECRQTSR: Request Terminal State Report](https://control-codes.page/csi/decrqtsr/index.html.md): Ask for most of the terminal's settable state in one compact report, and send it back later to restore it.
- [XTWINOPS: Window Operations](https://control-codes.page/csi/xtwinops/index.html.md): Move, resize and raise the window, report its size and state, and save and restore its title.

## Private modes

- [?1049: Alternate Screen](https://control-codes.page/modes/altscreen/index.html.md): Switch to a second screen for full-screen programs, and back to the one the shell was using.
- [DECARM: Autorepeat Mode](https://control-codes.page/modes/decarm/index.html.md): Turn the repeating of held-down keys on and off.
- [DECAWM: Autowrap Mode](https://control-codes.page/modes/decawm/index.html.md): Choose whether text reaching the right margin continues on the next line.
- [?2004: Bracketed Paste](https://control-codes.page/modes/paste/index.html.md): Mark pasted text, so that a program can tell it from typing.
- [DECCOLM: Column Mode](https://control-codes.page/modes/deccolm/index.html.md): Switch the screen between 80 and 132 columns, clearing it.
- [?12: Cursor Blink](https://control-codes.page/modes/blink/index.html.md): Start or stop the cursor blinking.
- [DECHCCM: Horizontal Cursor Coupling Mode](https://control-codes.page/modes/dechccm/index.html.md): Choose whether the window follows the cursor around a page larger than the screen.
- [DECCKM: Cursor Keys Mode](https://control-codes.page/modes/decckm/index.html.md): Choose what the arrow keys send: cursor movement or application codes.
- [?1004: Focus Events](https://control-codes.page/modes/focus/index.html.md): Have the terminal tell the program when its window gains or loses the keyboard focus.
- [DECKBUM: Keyboard Usage Mode](https://control-codes.page/modes/deckbum/index.html.md): Choose between typewriter keys and data processing keys.
- [?1000: Mouse Tracking](https://control-codes.page/modes/mouse/index.html.md): Ask the terminal to report mouse buttons and movement, and choose how the reports are encoded.
- [DECNRCM: National Replacement Character Set Mode](https://control-codes.page/modes/decnrcm/index.html.md): Allow the 7-bit national character sets, which replace a few ASCII characters with letters of one language.
- [DECOM: Origin Mode](https://control-codes.page/modes/decom/index.html.md): Count cursor positions from the margins instead of the corner of the screen.
- [DECPEX: Print Extent Mode](https://control-codes.page/modes/decpex/index.html.md): Choose what a print operation sends to the printer, and whether it ends with a form feed.
- [DECSCNM: Screen Mode](https://control-codes.page/modes/decscnm/index.html.md): Show the whole screen in reverse video: dark text on a light background.
- [DECSCLM: Scrolling Mode](https://control-codes.page/modes/decsclm/index.html.md): Choose between jump scrolling and smooth, slow scrolling.
- [?2026: Synchronized Output](https://control-codes.page/modes/sync/index.html.md): Hold back drawing the screen until a program has finished updating it.
- [DECTCEM: Text Cursor Enable Mode](https://control-codes.page/modes/dectcem/index.html.md): Show or hide the cursor.

## Operating system commands

- [OSC 4: Change Color Palette](https://control-codes.page/osc/palette/index.html.md): Set, query and reset the colors that SGR's color numbers stand for.
- [OSC 10: Change Dynamic Colors](https://control-codes.page/osc/dynamic/index.html.md): Set, query and reset the default foreground and background, the cursor's color, and others.
- [OSC 52: Manipulate Selection Data](https://control-codes.page/osc/clipboard/index.html.md): Let a program set or read the clipboard, even over ssh.
- [OSC 3008: Hierarchical Context Signalling](https://control-codes.page/osc/context/index.html.md): Tell the terminal when a shell, a command, a container or a privileged session starts and ends.
- [OSC 8: Hyperlink](https://control-codes.page/osc/hyperlink/index.html.md): Make text a link, the way an anchor does in HTML.
- [OSC 1337: iTerm2 Extensions](https://control-codes.page/osc/iterm2/index.html.md): iTerm2's own commands: inline images, marks, user variables, the clipboard and the working directory, and its other OSC extensions.
- [OSC 21: Kitty Color Protocol](https://control-codes.page/osc/kitty-color/index.html.md): Query and set the palette and the special colors by name, kitty's alternative to OSC 4 and OSC 10.
- [OSC 99: Kitty Extensions](https://control-codes.page/osc/kitty/index.html.md): Text sizing, drag and drop, notifications and the clipboard, as kitty defines them.
- [OSC 9: Desktop Notification](https://control-codes.page/osc/notify/index.html.md): Ask the terminal to show a desktop notification.
- [OSC 22: Change Pointer Shape](https://control-codes.page/osc/pointer/index.html.md): Change the shape of the mouse pointer while it is over the terminal.
- [OSC 9 ; 4: Progress Report](https://control-codes.page/osc/conemu/index.html.md): Show a program's progress in the tab and the taskbar, and ConEmu's other OSC 9 commands.
- [OSC 2: Set Window Title](https://control-codes.page/osc/title/index.html.md): Set the title of the terminal's window or tab.
- [OSC 133: Semantic Prompt](https://control-codes.page/osc/prompt/index.html.md): Mark where a shell's prompt, the command typed at it, and the command's output begin and end.
- [OSC 7: Report Working Directory](https://control-codes.page/osc/cwd/index.html.md): Tell the terminal which directory the shell is in.

## Parsing

- [C0 in sequences: Controls Inside Sequences](https://control-codes.page/parser/controls/index.html.md): What a control character does when it arrives in the middle of a control sequence or a string.
- [Parameters: Parameters](https://control-codes.page/parser/parameters/index.html.md): How many parameters a control sequence can carry, and what happens to ones that are malformed.
- [UTF-8: UTF-8 and C1 Controls](https://control-codes.page/parser/utf8/index.html.md): What a terminal reading UTF-8 does with bytes that are not valid UTF-8, and with the C1 controls.

## Guides

- [Notation](https://control-codes.page/notation/index.html.md): How syntax diagrams and validation cases are written on this site.
- [Sources](https://control-codes.page/sources/index.html.md): The documents each sequence page cites, and how the citations link to them.
- [The Rest of ECMA-48](https://control-codes.page/catalog/index.html.md): The ECMA-48 control functions that terminals do not use, grouped by what they were for.

---

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