Home / Guides

CRLF vs LF: Which Line Ending to Use, and How to Convert

Published 2026-11-05

LF (line feed, \n) is a single character that ends a line on Linux, macOS and the web. CRLF is two characters, carriage return plus line feed (\r\n), and it ends a line on Windows. Use LF for code, scripts and files shared between systems, and keep CRLF only where a format asks for it. This guide helps you choose for each situation, explains the problems the mismatch causes, and shows how to check and convert line endings in editors, Git and the command line.

CRLF vs LF in one table

LFCRLF
NameLine feed, also called newlineCarriage return + line feed
Characters12
Code pointsU+000AU+000D U+000A
Decimal and hex10, 0A13 10, 0D 0A
Escape\n\r\n
Used byLinux, macOS, Android, iOS, Unix tools, most modern code repositoriesWindows, HTTP headers, SMTP email, the CSV standard

The older Mac systems up to version 9 used a lone carriage return (CR). You rarely meet it now. The history of the two characters, from typewriters to teleprinters, is in our guide to carriage return and line feed, so this page sticks to the practical side.

What is a line feed?

A line feed is the control character that moves the text position down to the next line. It is character number 10 in ASCII and Unicode. Programming languages write it as \n and call it a newline. A line feed is not the same as a form feed (U+000C), which started a new page on a printer, or a vertical tab (U+000B). The cleaner treats the last two as control codes and removes them when invisible characters are being removed, but it keeps the line feed itself.

Which one should you use?

SituationUseWhy
Source code in a shared repositoryLFAvoids whole-file diffs when people use different systems
Shell scripts, Makefiles, DockerfilesLFUnix tools read a trailing CR as part of the last word on the line
Windows batch files (.bat, .cmd)CRLFWindows tools expect it, and labels can misbehave with LF only
CSV filesCRLF is the written standard; LF is accepted by most readersMatch whatever the receiving program expects
Text for web forms and the webLFHTML and JavaScript use LF inside text
Plain notes on your own computerEitherModern editors handle both

The rule of thumb: pick one for each project, write it down in the repository, and let tools enforce it.

Problems caused by a mismatch

How to check which line endings a file has

ToolHow
Visual Studio CodeThe status bar at the bottom right shows LF or CRLF
Notepad on WindowsThe status bar shows Windows (CRLF), Unix (LF) or Macintosh (CR)
Notepad++View > Show Symbol > Show End of Line
Vim:set ff? answers unix, dos or mac
Command linefile notes.txt mentions CRLF line terminators when it finds them
Gitgit ls-files --eol shows the endings in the index and in the working tree for each file

How to convert

In an editor

In Visual Studio Code, click LF or CRLF in the status bar, choose the other one and save. The setting files.eol controls which ending new files get. In Notepad++, use Edit > EOL Conversion. In Vim, :set ff=unix or :set ff=dos, then write the file.

On the command line

dos2unix input.txt                 # CRLF to LF, if the tool is installed
unix2dos input.txt                 # LF to CRLF
tr -d '\r' < input.txt > output.txt # remove every CR

In Git

The cleanest approach is a .gitattributes file in the repository, because it applies to everyone who clones it:

* text=auto
*.sh text eol=lf
*.bat text eol=crlf

The per-machine setting core.autocrlf does a similar job. With true, Git converts LF to CRLF when checking out and back to LF when committing. With input, it converts to LF on commit and leaves checkouts alone. A shared .editorconfig with end_of_line = lf keeps editors in line too.

In Python

Text mode translates line endings for you. To read a file exactly as it is, open it with newline="". To write LF on every system, pass newline="\n" when opening the file for writing.

In a spreadsheet

=SUBSTITUTE(A1, CHAR(13), "")

A line break typed inside a cell with Alt + Enter is a line feed, character 10.

What the AI Text Cleaner does with line endings

Every CRLF pair and every lone CR in the text becomes a single LF. This always happens, there is no switch for it, and the tool cannot produce CRLF. The cleaned text therefore always has LF endings, which is what web forms and most code editors expect. The vertical tab, form feed and next-line character (U+0085) are deleted when Remove invisible characters is on. Runs of three or more line breaks are collapsed to one blank line unless you switch that off, and paragraph breaks stay. To remove line breaks completely, see how to remove line breaks.

Common mistakes

Quick answers

What is the difference between CRLF and LF? LF is one character, used by Unix-like systems. CRLF is two characters, used by Windows.

Should I use CRLF or LF in Git? Store LF in the repository and use .gitattributes to say which files need CRLF in the working tree.

What does ^M mean? It is how many Unix tools display a carriage return, and shows that a file has Windows line endings.

Does Windows still need CRLF? Most modern Windows programs read both. Batch files and some older tools still prefer CRLF.

Text with mixed line endings? Anything you paste into the cleaner comes out with plain line feeds, and the cleaner removes hidden characters and odd spaces at the same time. Open the AI Text Cleaner

Related guides