Convert line breaks to br tags, or br tags back to line breaks

Paste text with line breaks, such as an address or a poem, and get HTML where every new line becomes a br tag, with the text escaped first so it displays exactly as typed; or reverse the process and turn br tags back into new lines.

Live demo · real result from this tool
Direction

HTML

Asha Rao<br>42 Lake View Road<br>Bengaluru 560001<br><br>Thanks for your order!

Preview

Processed on your device — nothing is uploaded.

How to use the newline to BR converter

  1. Paste your text into the Text box.
  2. Choose the Direction: New lines → <br> or <br> → new lines.
  3. For new lines to br, set the options: XHTML style <br />, Escape HTML in the text first (on by default) and Blank lines start new <p> paragraphs.
  4. Copy the HTML. A Preview below it shows how the browser will display it.

What it does and when to use it

Text from a form, a spreadsheet cell or a plain-text email keeps its line breaks only as invisible characters. Put it into a web page and everything runs together on one line. This tool adds explicit breaks, so a delivery address, a recipe step list, song credits or a short message keeps its shape.

The reverse direction is for text going the other way: copying content out of a CMS or an HTML email into a text field, a CSV or a chat, where <br> would show up as literal tags. For a full conversion of HTML with paragraphs and lists, use HTML to Text. If the text contains characters you want to see as codes, the HTML Encoder shows the escaped form on its own.

How it works

With escaping on, &, <, >, " and ' are replaced by their HTML entities first. Then each line ending, \n or \r\n, gets a <br> (or <br />) placed in front of it. In paragraph mode the text is split at blank lines, each block is trimmed and wrapped in <p>…</p>, and single line breaks inside a block become br tags. The br to new line mode replaces every <br>, <br/> or <BR /> and a line break right after it with one new line. It all runs in your browser.

Worked examples

An address with a blank line. The sample gives:

Asha Rao<br>
42 Lake View Road<br>
Bengaluru 560001<br>
<br>
Thanks for your order!

Paragraphs and XHTML. Tick both options and the same text becomes two paragraphs:

<p>Asha Rao<br />
42 Lake View Road<br />
Bengaluru 560001</p>
<p>Thanks for your order!</p>

Escaping. The two lines Use <b> for bold and and & for and become Use &lt;b&gt; for bold<br> and and &amp; for and, so the page shows the tag name as text instead of turning the rest bold.

Back to new lines. Line one<br />, a new line, then Line two<BR>Line three gives three plain lines.

Limits and tips

  • Spaces are not changed. Several spaces in a row still collapse to one in the browser; use a pre element if the spacing matters.
  • In paragraph mode, a line with only spaces counts as blank.
  • For many short lines that form a list, a real list is better for screen readers. Build one with the HTML List Generator.

Frequently asked questions

Why do my line breaks disappear in HTML?
Browsers treat a new line in HTML source as an ordinary space. To show a line break, the HTML needs a br tag, a new paragraph, or CSS such as white-space pre-line on the element. This tool adds the br tags for you.
Is this the same as PHP nl2br?
Yes, for the default settings. Like nl2br, it inserts the tag before each line break and keeps the original new line, so the HTML source stays readable. Windows CRLF line endings are handled too.
Should I use br tags or paragraphs?
Use br for line breaks that belong together, such as the lines of an address or a poem. Use paragraphs for separate blocks of text. With "Blank lines start new p paragraphs" ticked, the tool does both, which is right for most pasted text.
When should I turn off "Escape HTML in the text first"?
Only when the text already contains HTML that you want to keep as markup, such as bold tags. Leave it on for text typed by someone else. Escaping stops a stray less-than sign from breaking the page or running code.
Does br to new lines also remove other tags?
No. It only replaces br tags, in any case and with or without the slash, and leaves everything else. To remove all tags, use HTML to Text.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close