Skip to content
Home

Newline (line break)

A newline is a control character or sequence that marks the end of a line of text. It has multiple encodings (LF, CR, CRLF), historical origins in printing/teletypes, and practical effects in computing and networking.

A newline, often called a line feed or line break, is a control character or sequence used to mark the end of one line of text and the start of the next. In plain text files and many programming languages it determines how text is laid out on screen and printer output. Different systems and standards use different characters or combinations for the same logical action of moving to a following line.

Image gallery

2 Images

Characteristics and encodings

The most common encodings are the line feed (LF) and carriage return (CR). In ASCII and Unicode these are U+000A (LF) and U+000D (CR). LF is sometimes called line feed because it advances the paper one line in mechanical printers. CR is short for carriage return, originally returning the print head to the left margin. Some systems combine both characters in the sequence CR+LF (written CRLF) to perform both actions.

  • LF alone: used by modern Unix-like systems (illustrated in many programming languages by the escape \n).
  • CRLF: historically used by Microsoft Windows and in many Internet text-based protocols.
  • CR alone: used by older classic Mac OS versions; modern macOS uses LF like Unix.
  • Unicode also defines U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR) for unambiguous line/paragraph breaks.

History and origin

The distinction between CR and LF comes from mechanical typewriters and teletypes. A typewriter required two actions to start a new printed line: returning the carriage to the left margin and advancing the paper one line. Early teleprinter equipment and terminal protocols retained that split behavior, which carried into early computer character standards. Over time different platforms adopted different conventions, producing the variety seen today.

Uses, examples and practical effects

In programming, the newline influences string literals, file contents, and text rendering. Many languages use the escape sequence \n to represent a newline (typically LF). Network and Internet protocols such as SMTP and HTTP specify CRLF as the end-of-line marker in header and protocol lines. When transferring files between systems with different conventions, mismatched newline sequences can cause display or processing issues, diffs in version control, or problems with scripts that expect a particular form.

Handling and normalization

Text editors, version-control systems and libraries often provide newline normalization: converting various newline representations to a chosen internal form to avoid spurious differences. When interoperating with external systems, applications should be explicit about which newline convention they accept and produce. For display purposes, graphical environments usually render any newline sequence as a line break, while some text-processing tools treat Unicode line/paragraph separators differently from ASCII control characters.

Notable distinctions

  • Logical newline versus physical device action: the concept can map to different low-level characters depending on platform.
  • Protocol requirements: some standards mandate CRLF and will reject lines terminated by only LF.
  • Human factors: inconsistent newline handling is a common source of bugs when moving text between systems.

Understanding newline conventions is essential for reliable text processing, cross-platform software, and network communication. Tools and libraries that normalize or explicitly control line endings reduce interoperability problems and make behavior predictable across environments.

Related articles

Author

AlegsaOnline.com Newline (line break)

URL: https://en.alegsaonline.com/art/69756

Share