Skip to main content

CR

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Standard

CR (Carriage Return) is a C0 control character that moves the cursor to the beginning of the current line without advancing to the next line.

Syntax​

CR        0x0D
Formal syntax
CR = 0x0d ;

Description​

Per ECMA-48 §8.3.15, CR causes the active presentation position to be moved to the line home position of the same line. In standard terminal usage, this means column 1 of the current line.

CR does not erase any characters on the line. Any subsequent output will overwrite existing characters starting from the beginning of the line.

Interaction with LF​

In Unix systems, the newline character LF (0x0A) is the standard line terminator. The terminal driver's onlcr setting (on by default) typically translates output LF to CR+LF so that the cursor returns to column 1 when advancing to the next line. When the terminal is in raw mode, LF alone moves down without returning to column 1.

LNM mode​

When the Line Feed/New Line Mode (LNM, DECSET mode 20) is set, a received CR causes both a carriage return and a line feed, effectively acting as a "new line" operation.

Examples​

printf 'Hello\rWorld'   # Overwrites "Hello" with "World"
printf 'ABCDEF\rXY' # Displays "XYCDEF"

Specifications​

SpecificationSection
ECMA-48§8.3.15

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓YesHandler carriage_return() at term/mod.rs:1412
Bobcat✓0.9.0Basic C0 control, handled in TerminalCtrl library
contour✓v0.1.0Implemented in executeControlCode; calls moveCursorToBeginOfLine()
foot✓YesImplemented in vt.c:236-238
Ghostty✓v1.0.0Handled in stream.zig:771 as C0.CR (0x0D)
iTerm2✓Yes
Kitty✓Yes
Konsole✓Yes
mintty✓YesHandled in do_ctrl() at src/termout.c:1703
mlterm✓rel-0_2_1
PuTTY✓0.45
Rio✓v0.0.28
rxvt-unicode✓rxvt-unicode-1.2
st✓0.6
terminology✓v0.1.0
VT100✓Yes
VTE✓Yes
WezTerm✓YesHandled in performer.rs:402 via ControlCode::CarriageReturn, respects left/right margins
Windows Terminal✓YesHandled via CarriageReturn() dispatch in OutputStateMachineEngine.cpp:65-66
xterm✓YesImplemented in charproc.c:3706 via CarriageReturn()
xterm.js✓2.3.0
Multiplexers
cy✓v0.1.0
GNU Screen✓v.4.2.0Implemented in Special() function at src/ansi.c:681
tmux✓0.8Implemented via screen_write_carriagereturn()
tuios✓v0.0.15
Zellij✓v0.5.0-beta

See also​