October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Replace chr(13) with HTML
Line Breaks

Character 13 is carriage return, but not every line ending is CR. Match CR, LF or CRLF deliberately, and replace CRLF first to avoid duplicate HTML breaks.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Replace character 13 (carriage return, CR or r) with <br> only when your output is HTML and a visual line break is what you intend. First identify whether the input contains CR, LF, or the two-character CRLF sequence; the replacement must match that form.

What chr(13) and <br> mean

Character 13 is the carriage-return character, commonly written as r or U+000D. The HTML <br> element produces a line break in text. It is appropriate when the line division itself matters, such as in a poem or postal address (MDN Web Docs).

<br> is markup, not a replacement for paragraph structure. Do not use repeated <br> elements to create vertical margins between paragraphs; use separate <p> elements and CSS spacing instead.

Check the actual line-ending sequence

HTML recognizes three common newline forms: CR (U+000D), LF (U+000A), and CRLF (CR followed by LF), as specified by the WHATWG HTML Standard.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Input Typical notation Replacement to make one HTML line break
Carriage return r / character 13 Replace the lone CR with <br>
Line feed n / character 10 Replace LF with <br>
Carriage return + line feed rn Replace the two-character sequence once, before handling lone CR or LF

If CRLF is processed as separate characters, the CR can become one <br> and the following LF another, producing an unintended double break. Handle CRLF first whenever your input may contain it.

Language-neutral replacement logic

  1. Determine whether the destination will interpret HTML. If it displays plain text, inserting <br> will show the literal characters rather than create a break.
  2. Replace every CRLF sequence with <br>.
  3. Replace any remaining lone CR with <br>.
  4. If the input convention uses LF, replace remaining LF characters as well.

In pseudocode, the ordering is:

  1. text = replace(text, CRLF, "<br>")
  2. text = replace(text, CR, "<br>")
  3. text = replace(text, LF, "<br>") when LF is also a line boundary you intend to render

The exact function names and string-literal syntax depend on your programming language, so do not copy this pseudocode as a language-specific program without adapting it.

Python example

Python documents n as line feed, r as carriage return, and rn as their two-character combination. Its str.splitlines() method recognizes CR, LF, and CRLF among line boundaries (Python built-in types documentation).

For Python input where each recognized line boundary should become one HTML break, split into lines and join with the markup:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

html = "<br>".join(text.splitlines())

This approach treats the recognized boundaries as boundaries rather than attempting to replace character 13 alone. If preserving empty lines or trailing line endings is important, use explicit CRLF, CR, and LF replacements instead and test those cases against your input.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a paragraph is the right output

If the source uses line endings to separate paragraphs rather than lines within one address, poem, or similar block, convert those logical paragraphs to <p> elements instead of emitting a long sequence of <br> tags. Use CSS to control the space between paragraphs. The choice is about the intended document structure, not merely the numeric value 13.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Quick troubleshooting checklist

  • Nothing breaks: confirm the destination renders HTML rather than displaying escaped or plain text.
  • Every line has two breaks: your CRLF input was probably processed as separate CR and LF replacements; replace CRLF first.
  • Some lines remain joined: the source may use LF instead of CR, or a mixture of newline forms.
  • Too much vertical space: check whether paragraph spacing, CSS, or duplicate break tags are being added in addition to the converted line ending.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.